react-native-3rddigital-appupdate 1.0.9 → 1.0.11
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/README.md +50 -17
- package/lib/module/checkOTAUpdate.js +52 -7
- package/lib/module/checkOTAUpdate.js.map +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/checkOTAUpdate.d.ts +7 -0
- package/lib/typescript/src/checkOTAUpdate.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/checkOTAUpdate.ts +81 -7
- package/src/index.tsx +6 -1
package/README.md
CHANGED
|
@@ -33,25 +33,42 @@ cd ios && pod install
|
|
|
33
33
|
|
|
34
34
|
```sh
|
|
35
35
|
import React, { useEffect } from 'react';
|
|
36
|
-
import { View, Text } from 'react-native';
|
|
37
|
-
import {
|
|
36
|
+
import { Alert, View, Text } from 'react-native';
|
|
37
|
+
import {
|
|
38
|
+
OTAProvider,
|
|
39
|
+
checkOTAUpdate,
|
|
40
|
+
consumeOTAUpdateSuccessState,
|
|
41
|
+
} from 'react-native-3rddigital-appupdate';
|
|
38
42
|
|
|
39
43
|
const App = () => {
|
|
40
44
|
useEffect(() => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
45
|
+
const initializeOTAUpdate = async () => {
|
|
46
|
+
const updateState = await consumeOTAUpdateSuccessState();
|
|
47
|
+
|
|
48
|
+
if (updateState) {
|
|
49
|
+
Alert.alert(
|
|
50
|
+
'Update successful',
|
|
51
|
+
`OTA bundle v${updateState.version} is now active.`
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
await checkOTAUpdate({
|
|
56
|
+
baseUrl: 'https://your-api-url.com',
|
|
57
|
+
key: 'YOUR_PROJECT_KEY',
|
|
58
|
+
iosPackage: 'com.example.ios',
|
|
59
|
+
androidPackage: 'com.example.android',
|
|
60
|
+
loaderOptions: {
|
|
61
|
+
text: 'Downloading update...',
|
|
62
|
+
showProgress: true,
|
|
63
|
+
},
|
|
64
|
+
dialogOptions: {
|
|
65
|
+
title: 'Update Available',
|
|
66
|
+
message: 'A new version is ready to install.',
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
void initializeOTAUpdate();
|
|
55
72
|
}, []);
|
|
56
73
|
|
|
57
74
|
return (
|
|
@@ -66,6 +83,8 @@ const App = () => {
|
|
|
66
83
|
export default App;
|
|
67
84
|
```
|
|
68
85
|
|
|
86
|
+
If you already use a toast library, replace `Alert.alert(...)` with your toast call. The important part is calling `consumeOTAUpdateSuccessState()` once when the app starts so you can show a success message after the OTA-triggered reload.
|
|
87
|
+
|
|
69
88
|
## ⚙️ API Reference
|
|
70
89
|
|
|
71
90
|
🔹 checkOTAUpdate(options: OTAUpdateProps)
|
|
@@ -88,6 +107,20 @@ Options:
|
|
|
88
107
|
- Renders background components (AppLoader, AppAlertDialog) that handle UI for downloads and update prompts.
|
|
89
108
|
- Must be included once, usually at the root of your app.
|
|
90
109
|
|
|
110
|
+
🔹 consumeOTAUpdateSuccessState()
|
|
111
|
+
|
|
112
|
+
- Reads the one-time OTA success marker saved before app reload and clears it immediately after reading.
|
|
113
|
+
- Use this during app startup to show a success toast or alert after a bundle installs successfully.
|
|
114
|
+
|
|
115
|
+
Returns:
|
|
116
|
+
|
|
117
|
+
| Key | Type | Description |
|
|
118
|
+
| ------------- | -------- | ----------------------------------------- |
|
|
119
|
+
| `bundleId` | string | Bundle identifier returned by your server |
|
|
120
|
+
| `version` | number | Installed OTA bundle version |
|
|
121
|
+
| `appVersion` | string | Native app version associated with bundle |
|
|
122
|
+
| `installedAt` | string | ISO timestamp when install completed |
|
|
123
|
+
|
|
91
124
|
🔹 Loader (AppLoader)
|
|
92
125
|
|
|
93
126
|
- Global loader shown when downloading an update.
|
|
@@ -151,7 +184,7 @@ What it does
|
|
|
151
184
|
|
|
152
185
|
- Bundles your React Native JS + assets
|
|
153
186
|
- Zips the output
|
|
154
|
-
- Uploads bundle + metadata to your update server
|
|
187
|
+
- Uploads bundle + metadata to your update server
|
|
155
188
|
|
|
156
189
|
## 📄 License
|
|
157
190
|
|
|
@@ -7,6 +7,42 @@ import DeviceInfo from 'react-native-device-info';
|
|
|
7
7
|
import hotUpdate from 'react-native-ota-hot-update';
|
|
8
8
|
import { AppAlertDialog } from "./AppAlertDialog.js";
|
|
9
9
|
import { AppLoader } from "./AppLoader.js";
|
|
10
|
+
const OTA_UPDATE_SUCCESS_FILE = `${ReactNativeBlobUtil.fs.dirs.CacheDir}/ota-update-success.json`;
|
|
11
|
+
const persistOTAUpdateSuccessState = async state => {
|
|
12
|
+
try {
|
|
13
|
+
await ReactNativeBlobUtil.fs.writeFile(OTA_UPDATE_SUCCESS_FILE, JSON.stringify(state), 'utf8');
|
|
14
|
+
} catch (error) {
|
|
15
|
+
console.warn('Failed to persist OTA update success state:', error);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
const readOTAUpdateSuccessState = async () => {
|
|
19
|
+
try {
|
|
20
|
+
const exists = await ReactNativeBlobUtil.fs.exists(OTA_UPDATE_SUCCESS_FILE);
|
|
21
|
+
if (!exists) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
const content = await ReactNativeBlobUtil.fs.readFile(OTA_UPDATE_SUCCESS_FILE, 'utf8');
|
|
25
|
+
return JSON.parse(content);
|
|
26
|
+
} catch (error) {
|
|
27
|
+
console.warn('Failed to read OTA update success state:', error);
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
export const consumeOTAUpdateSuccessState = async () => {
|
|
32
|
+
const state = await readOTAUpdateSuccessState();
|
|
33
|
+
if (!state) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
const exists = await ReactNativeBlobUtil.fs.exists(OTA_UPDATE_SUCCESS_FILE);
|
|
38
|
+
if (exists) {
|
|
39
|
+
await ReactNativeBlobUtil.fs.unlink(OTA_UPDATE_SUCCESS_FILE);
|
|
40
|
+
}
|
|
41
|
+
} catch (error) {
|
|
42
|
+
console.warn('Failed to clear OTA update success state:', error);
|
|
43
|
+
}
|
|
44
|
+
return state;
|
|
45
|
+
};
|
|
10
46
|
export const checkOTAUpdate = async ({
|
|
11
47
|
key,
|
|
12
48
|
iosPackage,
|
|
@@ -39,13 +75,22 @@ export const checkOTAUpdate = async ({
|
|
|
39
75
|
}
|
|
40
76
|
},
|
|
41
77
|
updateSuccess: () => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
78
|
+
persistOTAUpdateSuccessState({
|
|
79
|
+
bundleId,
|
|
80
|
+
version,
|
|
81
|
+
appVersion: bundleAppVersion,
|
|
82
|
+
installedAt: new Date().toISOString()
|
|
83
|
+
}).finally(() => {
|
|
84
|
+
axios.post(`${API_URL}bundles/${bundleId}/count`, {
|
|
85
|
+
status: 'success'
|
|
86
|
+
}, {
|
|
87
|
+
headers: {
|
|
88
|
+
'Content-Type': 'application/json'
|
|
89
|
+
}
|
|
90
|
+
}).finally(() => AppLoader.hide());
|
|
91
|
+
}).catch(error => {
|
|
92
|
+
console.warn('Failed to finalize OTA update success handling:', error);
|
|
93
|
+
});
|
|
49
94
|
},
|
|
50
95
|
updateFail: error => {
|
|
51
96
|
axios.post(`${API_URL}bundles/${bundleId}/count`, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["axios","Platform","ReactNativeBlobUtil","DeviceInfo","hotUpdate","AppAlertDialog","AppLoader","checkOTAUpdate","key","iosPackage","androidPackage","loaderOptions","dialogOptions","baseUrl","API_URL","response","get","currentVersion","getCurrentVersion","data","OS","android","ios","version","forceUpdate","url","bundleId","currentAppVersion","getVersion","bundleAppVersion","appVersion","downloadAndReport","show","downloadBundleUri","progress","received","total","showProgress","percentage","Number","toFixed","updateProgress","updateSuccess","
|
|
1
|
+
{"version":3,"names":["axios","Platform","ReactNativeBlobUtil","DeviceInfo","hotUpdate","AppAlertDialog","AppLoader","OTA_UPDATE_SUCCESS_FILE","fs","dirs","CacheDir","persistOTAUpdateSuccessState","state","writeFile","JSON","stringify","error","console","warn","readOTAUpdateSuccessState","exists","content","readFile","parse","consumeOTAUpdateSuccessState","unlink","checkOTAUpdate","key","iosPackage","androidPackage","loaderOptions","dialogOptions","baseUrl","API_URL","response","get","currentVersion","getCurrentVersion","data","OS","android","ios","version","forceUpdate","url","bundleId","currentAppVersion","getVersion","bundleAppVersion","appVersion","downloadAndReport","show","downloadBundleUri","progress","received","total","showProgress","percentage","Number","toFixed","updateProgress","updateSuccess","installedAt","Date","toISOString","finally","post","status","headers","hide","catch","updateFail","deviceInfo","model","getModel","brand","getBrand","systemName","getSystemName","systemVersion","getSystemVersion","restartAfterInstall","restartDelay","showMessage","title","message","confirmText","cancelText","onConfirm","onCancel","err"],"sourceRoot":"../../src","sources":["checkOTAUpdate.ts"],"mappings":";;AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,QAAQ,QAAQ,cAAc;AACvC,OAAOC,mBAAmB,MAAM,wBAAwB;AACxD,OAAOC,UAAU,MAAM,0BAA0B;AACjD,OAAOC,SAAS,MAAM,6BAA6B;AACnD,SAASC,cAAc,QAA4B,qBAAkB;AACrE,SAASC,SAAS,QAA4B,gBAAa;AAkB3D,MAAMC,uBAAuB,GAAG,GAAGL,mBAAmB,CAACM,EAAE,CAACC,IAAI,CAACC,QAAQ,0BAA0B;AAEjG,MAAMC,4BAA4B,GAAG,MAAOC,KAA4B,IAAK;EAC3E,IAAI;IACF,MAAMV,mBAAmB,CAACM,EAAE,CAAC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pD,CAAC,CACAH,OAAO,CAAC,MAAM3D,SAAS,CAAC+D,IAAI,CAAC,CAAC,CAAC;QACpC,CAAC;QACDY,mBAAmB,EAAE,IAAI;QACzBC,YAAY,EAAE;MAChB,CAAC,CAAC;IACJ,CAAC;IAED,IAAIvC,WAAW,EAAE;MACfO,iBAAiB,CAAC,CAAC;IACrB,CAAC,MAAM;MACL7C,cAAc,CAAC8E,WAAW,CAAC;QACzBC,KAAK,EAAE,mBAAmB;QAC1BC,OAAO,EAAE,sCAAsC;QAC/CC,WAAW,EAAE,QAAQ;QACrBC,UAAU,EAAE,QAAQ;QACpBC,SAAS,EAAEtC,iBAAiB;QAC5BuC,QAAQ,EAAEA,CAAA,KAAM,CAAC,CAAC;QAClB,GAAG1D;MACL,CAAC,CAAC;IACJ;EACF,CAAC,CAAC,OAAO2D,GAAG,EAAE;IACZzE,OAAO,CAACC,IAAI,CAAC,0BAA0B,EAAEwE,GAAG,CAAC;EAC/C;AACF,CAAC","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["checkOTAUpdate","OTAProvider"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,
|
|
1
|
+
{"version":3,"names":["checkOTAUpdate","consumeOTAUpdateSuccessState","OTAProvider"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SACEA,cAAc,EACdC,4BAA4B,QAGvB,qBAAkB;AACzB,SAASC,WAAW,QAAQ,kBAAe","ignoreList":[]}
|
|
@@ -8,5 +8,12 @@ export type OTAUpdateProps = {
|
|
|
8
8
|
dialogOptions?: Omit<DialogOptions, 'onConfirm' | 'onCancel'>;
|
|
9
9
|
baseUrl: string;
|
|
10
10
|
};
|
|
11
|
+
export type OTAUpdateSuccessState = {
|
|
12
|
+
bundleId: string;
|
|
13
|
+
version: number;
|
|
14
|
+
appVersion: string;
|
|
15
|
+
installedAt: string;
|
|
16
|
+
};
|
|
17
|
+
export declare const consumeOTAUpdateSuccessState: () => Promise<OTAUpdateSuccessState | null>;
|
|
11
18
|
export declare const checkOTAUpdate: ({ key, iosPackage, androidPackage, loaderOptions, dialogOptions, baseUrl, }: OTAUpdateProps) => Promise<void>;
|
|
12
19
|
//# sourceMappingURL=checkOTAUpdate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkOTAUpdate.d.ts","sourceRoot":"","sources":["../../../src/checkOTAUpdate.ts"],"names":[],"mappings":"AAKA,OAAO,EAAkB,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAa,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5D,MAAM,MAAM,cAAc,GAAG;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,aAAa,CAAC,EAAE,IAAI,CAAC,aAAa,EAAE,WAAW,GAAG,UAAU,CAAC,CAAC;IAC9D,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,eAAO,MAAM,cAAc,GAAU,6EAOlC,cAAc,
|
|
1
|
+
{"version":3,"file":"checkOTAUpdate.d.ts","sourceRoot":"","sources":["../../../src/checkOTAUpdate.ts"],"names":[],"mappings":"AAKA,OAAO,EAAkB,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAa,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5D,MAAM,MAAM,cAAc,GAAG;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,aAAa,CAAC,EAAE,IAAI,CAAC,aAAa,EAAE,WAAW,GAAG,UAAU,CAAC,CAAC;IAC9D,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAmCF,eAAO,MAAM,4BAA4B,6CAkBxC,CAAC;AAEF,eAAO,MAAM,cAAc,GAAU,6EAOlC,cAAc,kBA+FhB,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { checkOTAUpdate, type OTAUpdateProps } from './checkOTAUpdate';
|
|
1
|
+
export { checkOTAUpdate, consumeOTAUpdateSuccessState, type OTAUpdateProps, type OTAUpdateSuccessState, } from './checkOTAUpdate';
|
|
2
2
|
export { OTAProvider } from './OTAProvider';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,4BAA4B,EAC5B,KAAK,cAAc,EACnB,KAAK,qBAAqB,GAC3B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-3rddigital-appupdate",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.11",
|
|
4
4
|
"description": "A React Native library for seamless over-the-air (OTA) updates with version checks, automatic bundle download, and customizable user prompts for iOS and Android.",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|
package/src/checkOTAUpdate.ts
CHANGED
|
@@ -15,6 +15,66 @@ export type OTAUpdateProps = {
|
|
|
15
15
|
baseUrl: string;
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
+
export type OTAUpdateSuccessState = {
|
|
19
|
+
bundleId: string;
|
|
20
|
+
version: number;
|
|
21
|
+
appVersion: string;
|
|
22
|
+
installedAt: string;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const OTA_UPDATE_SUCCESS_FILE = `${ReactNativeBlobUtil.fs.dirs.CacheDir}/ota-update-success.json`;
|
|
26
|
+
|
|
27
|
+
const persistOTAUpdateSuccessState = async (state: OTAUpdateSuccessState) => {
|
|
28
|
+
try {
|
|
29
|
+
await ReactNativeBlobUtil.fs.writeFile(
|
|
30
|
+
OTA_UPDATE_SUCCESS_FILE,
|
|
31
|
+
JSON.stringify(state),
|
|
32
|
+
'utf8'
|
|
33
|
+
);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
console.warn('Failed to persist OTA update success state:', error);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const readOTAUpdateSuccessState = async () => {
|
|
40
|
+
try {
|
|
41
|
+
const exists = await ReactNativeBlobUtil.fs.exists(OTA_UPDATE_SUCCESS_FILE);
|
|
42
|
+
|
|
43
|
+
if (!exists) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const content = await ReactNativeBlobUtil.fs.readFile(
|
|
48
|
+
OTA_UPDATE_SUCCESS_FILE,
|
|
49
|
+
'utf8'
|
|
50
|
+
);
|
|
51
|
+
return JSON.parse(content) as OTAUpdateSuccessState;
|
|
52
|
+
} catch (error) {
|
|
53
|
+
console.warn('Failed to read OTA update success state:', error);
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const consumeOTAUpdateSuccessState = async () => {
|
|
59
|
+
const state = await readOTAUpdateSuccessState();
|
|
60
|
+
|
|
61
|
+
if (!state) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
try {
|
|
66
|
+
const exists = await ReactNativeBlobUtil.fs.exists(OTA_UPDATE_SUCCESS_FILE);
|
|
67
|
+
|
|
68
|
+
if (exists) {
|
|
69
|
+
await ReactNativeBlobUtil.fs.unlink(OTA_UPDATE_SUCCESS_FILE);
|
|
70
|
+
}
|
|
71
|
+
} catch (error) {
|
|
72
|
+
console.warn('Failed to clear OTA update success state:', error);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return state;
|
|
76
|
+
};
|
|
77
|
+
|
|
18
78
|
export const checkOTAUpdate = async ({
|
|
19
79
|
key,
|
|
20
80
|
iosPackage,
|
|
@@ -56,13 +116,27 @@ export const checkOTAUpdate = async ({
|
|
|
56
116
|
}
|
|
57
117
|
},
|
|
58
118
|
updateSuccess: () => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
.finally(() =>
|
|
119
|
+
persistOTAUpdateSuccessState({
|
|
120
|
+
bundleId,
|
|
121
|
+
version,
|
|
122
|
+
appVersion: bundleAppVersion,
|
|
123
|
+
installedAt: new Date().toISOString(),
|
|
124
|
+
})
|
|
125
|
+
.finally(() => {
|
|
126
|
+
axios
|
|
127
|
+
.post(
|
|
128
|
+
`${API_URL}bundles/${bundleId}/count`,
|
|
129
|
+
{ status: 'success' },
|
|
130
|
+
{ headers: { 'Content-Type': 'application/json' } }
|
|
131
|
+
)
|
|
132
|
+
.finally(() => AppLoader.hide());
|
|
133
|
+
})
|
|
134
|
+
.catch((error) => {
|
|
135
|
+
console.warn(
|
|
136
|
+
'Failed to finalize OTA update success handling:',
|
|
137
|
+
error
|
|
138
|
+
);
|
|
139
|
+
});
|
|
66
140
|
},
|
|
67
141
|
updateFail: (error) => {
|
|
68
142
|
axios
|
package/src/index.tsx
CHANGED