@o/native-hot-update 0.16.19

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.
Files changed (44) hide show
  1. package/README.md +212 -0
  2. package/dist/cjs/createHotUpdater.cjs +224 -0
  3. package/dist/cjs/createHotUpdater.native.js +250 -0
  4. package/dist/cjs/createHotUpdater.native.js.map +1 -0
  5. package/dist/cjs/helpers.cjs +40 -0
  6. package/dist/cjs/helpers.native.js +43 -0
  7. package/dist/cjs/helpers.native.js.map +1 -0
  8. package/dist/cjs/index.cjs +31 -0
  9. package/dist/cjs/index.native.js +34 -0
  10. package/dist/cjs/index.native.js.map +1 -0
  11. package/dist/cjs/mmkv.cjs +34 -0
  12. package/dist/cjs/mmkv.native.js +43 -0
  13. package/dist/cjs/mmkv.native.js.map +1 -0
  14. package/dist/cjs/types.cjs +18 -0
  15. package/dist/cjs/types.native.js +21 -0
  16. package/dist/cjs/types.native.js.map +1 -0
  17. package/dist/esm/createHotUpdater.mjs +188 -0
  18. package/dist/esm/createHotUpdater.mjs.map +1 -0
  19. package/dist/esm/createHotUpdater.native.js +211 -0
  20. package/dist/esm/createHotUpdater.native.js.map +1 -0
  21. package/dist/esm/helpers.mjs +14 -0
  22. package/dist/esm/helpers.mjs.map +1 -0
  23. package/dist/esm/helpers.native.js +14 -0
  24. package/dist/esm/helpers.native.js.map +1 -0
  25. package/dist/esm/index.js +4 -0
  26. package/dist/esm/index.js.map +1 -0
  27. package/dist/esm/index.mjs +4 -0
  28. package/dist/esm/index.mjs.map +1 -0
  29. package/dist/esm/index.native.js +4 -0
  30. package/dist/esm/index.native.js.map +1 -0
  31. package/dist/esm/mmkv.mjs +9 -0
  32. package/dist/esm/mmkv.mjs.map +1 -0
  33. package/dist/esm/mmkv.native.js +15 -0
  34. package/dist/esm/mmkv.native.js.map +1 -0
  35. package/dist/esm/types.mjs +2 -0
  36. package/dist/esm/types.mjs.map +1 -0
  37. package/dist/esm/types.native.js +2 -0
  38. package/dist/esm/types.native.js.map +1 -0
  39. package/package.json +67 -0
  40. package/src/createHotUpdater.ts +250 -0
  41. package/src/helpers.ts +23 -0
  42. package/src/index.ts +6 -0
  43. package/src/mmkv.ts +20 -0
  44. package/src/types.ts +66 -0
@@ -0,0 +1,40 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: () => from[key],
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
+ value: true
22
+ }), mod);
23
+ var helpers_exports = {};
24
+ __export(helpers_exports, {
25
+ getAppliedOta: () => getAppliedOta,
26
+ getShortOtaId: () => getShortOtaId
27
+ });
28
+ module.exports = __toCommonJS(helpers_exports);
29
+ var import_react_native = require("@hot-updater/react-native");
30
+ const INITIAL_OTA_ID = "00000000-0000-0000-0000-000000000000";
31
+ function getAppliedOta() {
32
+ const id = import_react_native.HotUpdater.getBundleId();
33
+ if (id === INITIAL_OTA_ID) return null;
34
+ if (id === import_react_native.HotUpdater.getMinBundleId()) return null;
35
+ return id;
36
+ }
37
+ function getShortOtaId() {
38
+ const fullId = getAppliedOta();
39
+ return fullId ? fullId.slice(-12) : null;
40
+ }
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: () => from[key],
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
+ };
22
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
23
+ value: true
24
+ }), mod);
25
+ var helpers_exports = {};
26
+ __export(helpers_exports, {
27
+ getAppliedOta: () => getAppliedOta,
28
+ getShortOtaId: () => getShortOtaId
29
+ });
30
+ module.exports = __toCommonJS(helpers_exports);
31
+ var import_react_native = require("@hot-updater/react-native");
32
+ var INITIAL_OTA_ID = "00000000-0000-0000-0000-000000000000";
33
+ function getAppliedOta() {
34
+ var id = import_react_native.HotUpdater.getBundleId();
35
+ if (id === INITIAL_OTA_ID) return null;
36
+ if (id === import_react_native.HotUpdater.getMinBundleId()) return null;
37
+ return id;
38
+ }
39
+ function getShortOtaId() {
40
+ var fullId = getAppliedOta();
41
+ return fullId ? fullId.slice(-12) : null;
42
+ }
43
+ //# sourceMappingURL=helpers.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","helpers_exports","__export","getAppliedOta","getShortOtaId","module","exports","import_react_native","require","INITIAL_OTA_ID","id","HotUpdater","getBundleId","getMinBundleId","fullId","slice"],"sources":["../../src/helpers.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,eAAA;AAAAC,QAAA,CAAAD,eAAA;EAAAE,aAAA,EAAAA,CAAA,KAAAA,aAAA;EAAAC,aAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAV,YAA2B,CAAAK,eAAA;AAE3B,IAAAM,mBAAuB,GAAAC,OAAA;AAMhB,IAAAC,cAAS,yCAA+B;AAC7C,SAAMN,aAAKA,CAAA;EACX,IAAIO,EAAA,GAAAH,mBAAuB,CAAAI,UAAO,CAAAC,WAAA;EAClC,IAAIF,EAAA,KAAOD,cAAA;EACX,IAAAC,EAAA,KAAOH,mBAAA,CAAAI,UAAA,CAAAE,cAAA;EACT,OAAAH,EAAA;AAMO;AACL,SAAMN,aAASA,CAAA;EACf,IAAAU,MAAO,GAAAX,aAAgB;EACzB,OAAAW,MAAA,GAAAA,MAAA,CAAAC,KAAA","ignoreList":[]}
@@ -0,0 +1,31 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: () => from[key],
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
+ value: true
22
+ }), mod);
23
+ var index_exports = {};
24
+ __export(index_exports, {
25
+ HotUpdater: () => import_react_native.HotUpdater,
26
+ createHotUpdater: () => import_createHotUpdater.createHotUpdater,
27
+ useHotUpdaterStore: () => import_react_native.useHotUpdaterStore
28
+ });
29
+ module.exports = __toCommonJS(index_exports);
30
+ var import_react_native = require("@hot-updater/react-native");
31
+ var import_createHotUpdater = require("./createHotUpdater.cjs");
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: () => from[key],
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
+ };
22
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
23
+ value: true
24
+ }), mod);
25
+ var index_exports = {};
26
+ __export(index_exports, {
27
+ HotUpdater: () => import_react_native.HotUpdater,
28
+ createHotUpdater: () => import_createHotUpdater.createHotUpdater,
29
+ useHotUpdaterStore: () => import_react_native.useHotUpdaterStore
30
+ });
31
+ module.exports = __toCommonJS(index_exports);
32
+ var import_react_native = require("@hot-updater/react-native");
33
+ var import_createHotUpdater = require("./createHotUpdater.native.js");
34
+ //# sourceMappingURL=index.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","index_exports","__export","HotUpdater","import_react_native","createHotUpdater","import_createHotUpdater","useHotUpdaterStore","module","exports","require"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,aAAA;AAAAC,QAAA,CAAAD,aAAA;EAAAE,UAAA,EAAAA,CAAA,KAAAC,mBAAA,CAAAD,UAAA;EAAAE,gBAAA,EAAAA,CAAA,KAAAC,uBAAA,CAAAD,gBAAA;EAAAE,kBAAA,EAAAA,CAAA,KAAAH,mBAAA,CAAAG;AAAA;AACAC,MAAA,CAAAC,OAAA,GAAAb,YAA+C,CAAAK,aAAA;AAG/C,IAAAG,mBAAA,GAAAM,OAAiC","ignoreList":[]}
@@ -0,0 +1,34 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: () => from[key],
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
+ value: true
22
+ }), mod);
23
+ var mmkv_exports = {};
24
+ __export(mmkv_exports, {
25
+ createMMKVStorage: () => createMMKVStorage
26
+ });
27
+ module.exports = __toCommonJS(mmkv_exports);
28
+ function createMMKVStorage(mmkv) {
29
+ return {
30
+ get: key => mmkv.getString(key),
31
+ set: (key, value) => mmkv.set(key, value),
32
+ delete: key => mmkv.delete(key)
33
+ };
34
+ }
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: () => from[key],
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
+ };
22
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
23
+ value: true
24
+ }), mod);
25
+ var mmkv_exports = {};
26
+ __export(mmkv_exports, {
27
+ createMMKVStorage: () => createMMKVStorage
28
+ });
29
+ module.exports = __toCommonJS(mmkv_exports);
30
+ function createMMKVStorage(mmkv) {
31
+ return {
32
+ get: function get(key) {
33
+ return mmkv.getString(key);
34
+ },
35
+ set: function set(key, value) {
36
+ return mmkv.set(key, value);
37
+ },
38
+ delete: function _delete(key) {
39
+ return mmkv.delete(key);
40
+ }
41
+ };
42
+ }
43
+ //# sourceMappingURL=mmkv.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","mmkv_exports","__export","createMMKVStorage","module","exports","mmkv","get","key","getString","set"],"sources":["../../src/mmkv.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,YAAA;AAAAC,QAAA,CAAAD,YAAA;EAAAE,iBAAA,EAAAA,CAAA,KAAAA;AAAA;AAaOC,MAAA,CAAAC,OAAS,GAAAT,YAAkB,CAAAK,YAA8B;AAC9D,SAAOE,kBAAAG,IAAA;EAAA,OACA;IACLC,GAAA,EAAK,SAAcA,IAAAC,GAAkB;MACrC,OAASF,IAAA,CAAAG,SAAqB,CAAAD,GAAA;IAChC;IACFE,GAAA,WAAAA,IAAAF,GAAA,EAAAR,KAAA","ignoreList":[]}
@@ -0,0 +1,18 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
8
+ get: () => from[key],
9
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
10
+ });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
15
+ value: true
16
+ }), mod);
17
+ var types_exports = {};
18
+ module.exports = __toCommonJS(types_exports);
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __copyProps = (to, from, except, desc) => {
8
+ if (from && typeof from === "object" || typeof from === "function") {
9
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
10
+ get: () => from[key],
11
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
12
+ });
13
+ }
14
+ return to;
15
+ };
16
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
17
+ value: true
18
+ }), mod);
19
+ var types_exports = {};
20
+ module.exports = __toCommonJS(types_exports);
21
+ //# sourceMappingURL=types.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","types_exports"],"sources":["../../src/types.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,aAAA","ignoreList":[]}
@@ -0,0 +1,188 @@
1
+ import { HotUpdater, useHotUpdaterStore } from "@hot-updater/react-native";
2
+ import * as Application from "expo-application";
3
+ import { useEffect, useRef, useState } from "react";
4
+ import { Alert } from "react-native-web";
5
+ const INITIAL_OTA_ID = "00000000-0000-0000-0000-000000000000";
6
+ const BUNDLE_ID_KEY_PREFIX = "hotUpdater.bundleId";
7
+ const PRE_RELEASE_BUNDLE_ID_KEY = "hotUpdater.preReleaseBundleId";
8
+ function createHotUpdater(config) {
9
+ const {
10
+ storage,
11
+ updateStrategy = "appVersion"
12
+ } = config;
13
+ let isUpdatePending = false;
14
+ const getAppliedOta = () => {
15
+ const id = HotUpdater.getBundleId();
16
+ if (id === INITIAL_OTA_ID) return null;
17
+ if (id === HotUpdater.getMinBundleId()) return null;
18
+ return id;
19
+ };
20
+ const getShortOtaId = () => {
21
+ const fullId = getAppliedOta();
22
+ return fullId ? fullId.slice(-12) : null;
23
+ };
24
+ const getIsUpdatePending = () => {
25
+ return isUpdatePending;
26
+ };
27
+ const getPreReleaseBundleId = () => {
28
+ return storage.get(PRE_RELEASE_BUNDLE_ID_KEY);
29
+ };
30
+ const handleUpdateDownloaded = (id, options = {}) => {
31
+ const appVersion = Application.nativeApplicationVersion;
32
+ if (appVersion) {
33
+ storage.set(`${BUNDLE_ID_KEY_PREFIX}.${appVersion}`, id);
34
+ }
35
+ if (options.isPreRelease) {
36
+ storage.set(PRE_RELEASE_BUNDLE_ID_KEY, id);
37
+ } else {
38
+ storage.delete(PRE_RELEASE_BUNDLE_ID_KEY);
39
+ }
40
+ isUpdatePending = true;
41
+ };
42
+ const useOtaUpdater = (options = {}) => {
43
+ const {
44
+ enabled = true,
45
+ onUpdateDownloaded: onUpdateDownloadedCallback,
46
+ onError
47
+ } = options;
48
+ const progress = useHotUpdaterStore(state => state.progress);
49
+ const isUpdating = progress > 0.01;
50
+ const [isUserClearedForAccess, setIsUserClearedForAccess] = useState(false);
51
+ const isUserClearedForAccessRef = useRef(isUserClearedForAccess);
52
+ isUserClearedForAccessRef.current = isUserClearedForAccess;
53
+ useEffect(() => {
54
+ if (!isUpdating) {
55
+ const timer = setTimeout(() => {
56
+ if (!isUserClearedForAccessRef.current) {
57
+ setIsUserClearedForAccess(true);
58
+ }
59
+ }, 5e3);
60
+ return () => clearTimeout(timer);
61
+ }
62
+ return void 0;
63
+ }, [isUpdating]);
64
+ useEffect(() => {
65
+ const timer = setTimeout(() => {
66
+ if (!isUserClearedForAccessRef.current) {
67
+ setIsUserClearedForAccess(true);
68
+ }
69
+ }, 2e4);
70
+ return () => clearTimeout(timer);
71
+ }, []);
72
+ useEffect(() => {
73
+ let shouldContinue = true;
74
+ (async () => {
75
+ try {
76
+ if (!enabled) {
77
+ setIsUserClearedForAccess(true);
78
+ return;
79
+ }
80
+ if (!shouldContinue) return;
81
+ const updateInfo = await HotUpdater.checkForUpdate({
82
+ updateStrategy
83
+ });
84
+ if (!updateInfo) {
85
+ setIsUserClearedForAccess(true);
86
+ return;
87
+ }
88
+ if (!shouldContinue) return;
89
+ if (updateInfo.status === "ROLLBACK") {
90
+ const preReleaseBundleId = getPreReleaseBundleId();
91
+ const currentBundleId = HotUpdater.getBundleId();
92
+ if (preReleaseBundleId && preReleaseBundleId === currentBundleId && currentBundleId > updateInfo.id) {
93
+ Alert.alert("Update Skipped", "Skipped rollback because you are using a newer pre-release bundle.");
94
+ setIsUserClearedForAccess(true);
95
+ return;
96
+ }
97
+ }
98
+ if (!updateInfo.shouldForceUpdate) {
99
+ setIsUserClearedForAccess(true);
100
+ }
101
+ if (!shouldContinue) return;
102
+ await updateInfo.updateBundle();
103
+ handleUpdateDownloaded(updateInfo.id);
104
+ const info = {
105
+ id: updateInfo.id,
106
+ isCriticalUpdate: updateInfo.shouldForceUpdate,
107
+ fileUrl: updateInfo.fileUrl,
108
+ message: updateInfo.message
109
+ };
110
+ onUpdateDownloadedCallback?.(info);
111
+ if (!shouldContinue) return;
112
+ if (updateInfo.shouldForceUpdate) {
113
+ if (!isUserClearedForAccessRef.current) {
114
+ HotUpdater.reload();
115
+ return;
116
+ }
117
+ Alert.alert("Update Downloaded", "An important update has been downloaded. Reload now to apply it?", [{
118
+ text: "Later",
119
+ style: "cancel"
120
+ }, {
121
+ text: "Reload Now",
122
+ onPress: () => HotUpdater.reload()
123
+ }]);
124
+ }
125
+ } catch (error) {
126
+ onError?.(error);
127
+ setIsUserClearedForAccess(true);
128
+ } finally {
129
+ if (!isUserClearedForAccessRef.current) {
130
+ setIsUserClearedForAccess(true);
131
+ }
132
+ }
133
+ })();
134
+ return () => {
135
+ shouldContinue = false;
136
+ };
137
+ }, [enabled, onUpdateDownloadedCallback, onError]);
138
+ return {
139
+ userClearedForAccess: isUserClearedForAccess,
140
+ progress,
141
+ isUpdatePending: getIsUpdatePending()
142
+ };
143
+ };
144
+ const checkForUpdate = async (options = {}) => {
145
+ const {
146
+ channel,
147
+ isPreRelease = false
148
+ } = options;
149
+ const requestHeaders = {};
150
+ if (channel) {
151
+ requestHeaders["X-Channel"] = channel;
152
+ }
153
+ const updateInfo = await HotUpdater.checkForUpdate({
154
+ updateStrategy,
155
+ ...(Object.keys(requestHeaders).length > 0 && {
156
+ requestHeaders
157
+ })
158
+ });
159
+ if (updateInfo) {
160
+ await updateInfo.updateBundle();
161
+ handleUpdateDownloaded(updateInfo.id, {
162
+ isPreRelease
163
+ });
164
+ return {
165
+ id: updateInfo.id,
166
+ isCriticalUpdate: updateInfo.shouldForceUpdate,
167
+ fileUrl: updateInfo.fileUrl,
168
+ message: updateInfo.message
169
+ };
170
+ }
171
+ return null;
172
+ };
173
+ return {
174
+ useOtaUpdater,
175
+ checkForUpdate,
176
+ getAppliedOta,
177
+ getShortOtaId,
178
+ getIsUpdatePending,
179
+ reload: () => HotUpdater.reload(),
180
+ getBundleId: () => HotUpdater.getBundleId(),
181
+ getMinBundleId: () => HotUpdater.getMinBundleId(),
182
+ getChannel: () => HotUpdater.getChannel(),
183
+ clearCrashHistory: () => HotUpdater.clearCrashHistory(),
184
+ getCrashHistory: () => HotUpdater.getCrashHistory()
185
+ };
186
+ }
187
+ export { createHotUpdater };
188
+ //# sourceMappingURL=createHotUpdater.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["HotUpdater","useHotUpdaterStore","Application","useEffect","useRef","useState","Alert","INITIAL_OTA_ID","BUNDLE_ID_KEY_PREFIX","PRE_RELEASE_BUNDLE_ID_KEY","createHotUpdater","config","storage","updateStrategy","isUpdatePending","getAppliedOta","id","getBundleId","getMinBundleId","getShortOtaId","fullId","slice","getIsUpdatePending","getPreReleaseBundleId","get","handleUpdateDownloaded","options","appVersion","nativeApplicationVersion","set","isPreRelease","delete","useOtaUpdater","enabled","onUpdateDownloaded","onUpdateDownloadedCallback","onError","progress","state","isUpdating","isUserClearedForAccess","setIsUserClearedForAccess","isUserClearedForAccessRef","current","timer","setTimeout","clearTimeout","shouldContinue","updateInfo","checkForUpdate","status","preReleaseBundleId","currentBundleId","alert","shouldForceUpdate","updateBundle","info","isCriticalUpdate","fileUrl","message","reload","text","style","onPress","error","userClearedForAccess","channel","requestHeaders","Object","keys","length","getChannel","clearCrashHistory","getCrashHistory"],"sources":["../../src/createHotUpdater.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,UAAA,EAAYC,kBAAA,QAA0B;AAC/C,YAAYC,WAAA,MAAiB;AAC7B,SAASC,SAAA,EAAWC,MAAA,EAAQC,QAAA,QAAgB;AAC5C,SAASC,KAAA,QAAa;AAItB,MAAMC,cAAA,GAAiB;AACvB,MAAMC,oBAAA,GAAuB;AAC7B,MAAMC,yBAAA,GAA4B;AAM3B,SAASC,iBAAiBC,MAAA,EAA8C;EAC7E,MAAM;IAAEC,OAAA;IAASC,cAAA,GAAiB;EAAa,IAAIF,MAAA;EAEnD,IAAIG,eAAA,GAAkB;EAEtB,MAAMC,aAAA,GAAgBA,CAAA,KA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