@hot-updater/js 0.1.6-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/dist/checkForRollback.d.ts +2 -0
- package/dist/checkForRollback.test.d.ts +1 -0
- package/dist/getUpdateInfo.d.ts +2 -0
- package/dist/getUpdateInfo.test.d.ts +1 -0
- package/dist/index.cjs +108 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +60 -0
- package/dist/semverSatisfies.d.ts +1 -0
- package/dist/semverSatisfies.spec.d.ts +1 -0
- package/dist/utils.d.ts +1 -0
- package/package.json +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Sungyu Kang
|
|
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.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = function(module) {
|
|
5
|
+
var getter = module && module.__esModule ? function() {
|
|
6
|
+
return module['default'];
|
|
7
|
+
} : function() {
|
|
8
|
+
return module;
|
|
9
|
+
};
|
|
10
|
+
__webpack_require__.d(getter, {
|
|
11
|
+
a: getter
|
|
12
|
+
});
|
|
13
|
+
return getter;
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
(()=>{
|
|
17
|
+
__webpack_require__.d = function(exports1, definition) {
|
|
18
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: definition[key]
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
(()=>{
|
|
25
|
+
__webpack_require__.o = function(obj, prop) {
|
|
26
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
27
|
+
};
|
|
28
|
+
})();
|
|
29
|
+
(()=>{
|
|
30
|
+
__webpack_require__.r = function(exports1) {
|
|
31
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
32
|
+
value: 'Module'
|
|
33
|
+
});
|
|
34
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
35
|
+
value: true
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
var __webpack_exports__ = {};
|
|
40
|
+
__webpack_require__.r(__webpack_exports__);
|
|
41
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
42
|
+
getUpdateInfo: ()=>getUpdateInfo
|
|
43
|
+
});
|
|
44
|
+
const core_namespaceObject = require("@hot-updater/core");
|
|
45
|
+
const isNullable = (value)=>null == value;
|
|
46
|
+
const checkForRollback = (bundles, currentBundleId)=>{
|
|
47
|
+
if (currentBundleId === core_namespaceObject.NIL_UUID) return false;
|
|
48
|
+
if (0 === bundles.length) return true;
|
|
49
|
+
const enabled = bundles.find((item)=>item.id === currentBundleId)?.enabled;
|
|
50
|
+
const availableOldVersion = bundles.find((item)=>item.id.localeCompare(currentBundleId) < 0 && item.enabled)?.enabled;
|
|
51
|
+
if (isNullable(enabled)) return Boolean(availableOldVersion);
|
|
52
|
+
return !enabled;
|
|
53
|
+
};
|
|
54
|
+
const external_semver_namespaceObject = require("semver");
|
|
55
|
+
var external_semver_default = /*#__PURE__*/ __webpack_require__.n(external_semver_namespaceObject);
|
|
56
|
+
const semverSatisfies = (targetVersion, currentVersion)=>{
|
|
57
|
+
const currentCoerce = external_semver_default().coerce(currentVersion);
|
|
58
|
+
if (!currentCoerce) throw new Error("Invalid current version");
|
|
59
|
+
return external_semver_default().satisfies(currentCoerce.version, targetVersion);
|
|
60
|
+
};
|
|
61
|
+
const findLatestBundles = (bundles)=>bundles?.filter((item)=>item.enabled)?.sort((a, b)=>b.id.localeCompare(a.id))?.[0] ?? null;
|
|
62
|
+
const getUpdateInfo = async (bundles, { platform, bundleId, appVersion })=>{
|
|
63
|
+
const filteredBundles = bundles.filter((b)=>b.platform === platform && semverSatisfies(b.targetVersion, appVersion));
|
|
64
|
+
const isRollback = checkForRollback(filteredBundles, bundleId);
|
|
65
|
+
const latestBundle = await findLatestBundles(filteredBundles);
|
|
66
|
+
if (!latestBundle) {
|
|
67
|
+
if (isRollback) return {
|
|
68
|
+
id: core_namespaceObject.NIL_UUID,
|
|
69
|
+
forceUpdate: true,
|
|
70
|
+
fileUrl: null,
|
|
71
|
+
fileHash: null,
|
|
72
|
+
status: "ROLLBACK"
|
|
73
|
+
};
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
if (latestBundle.fileUrl) {
|
|
77
|
+
if (isRollback) {
|
|
78
|
+
if (latestBundle.id === bundleId) return null;
|
|
79
|
+
if (latestBundle.id.localeCompare(bundleId) > 0) return {
|
|
80
|
+
id: latestBundle.id,
|
|
81
|
+
forceUpdate: latestBundle.forceUpdate,
|
|
82
|
+
fileUrl: latestBundle.fileUrl,
|
|
83
|
+
fileHash: latestBundle.fileHash,
|
|
84
|
+
status: "UPDATE"
|
|
85
|
+
};
|
|
86
|
+
return {
|
|
87
|
+
id: latestBundle.id,
|
|
88
|
+
forceUpdate: true,
|
|
89
|
+
fileUrl: latestBundle.fileUrl,
|
|
90
|
+
fileHash: latestBundle.fileHash,
|
|
91
|
+
status: "ROLLBACK"
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (latestBundle.id.localeCompare(bundleId) > 0) return {
|
|
96
|
+
id: latestBundle.id,
|
|
97
|
+
forceUpdate: latestBundle.forceUpdate,
|
|
98
|
+
fileUrl: latestBundle.fileUrl,
|
|
99
|
+
fileHash: latestBundle.fileHash,
|
|
100
|
+
status: "UPDATE"
|
|
101
|
+
};
|
|
102
|
+
return null;
|
|
103
|
+
};
|
|
104
|
+
var __webpack_export_target__ = exports;
|
|
105
|
+
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
106
|
+
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
|
|
107
|
+
value: true
|
|
108
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./getUpdateInfo";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE__hot_updater_core__ from "@hot-updater/core";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE_semver__ from "semver";
|
|
3
|
+
const isNullable = (value)=>null == value;
|
|
4
|
+
const checkForRollback = (bundles, currentBundleId)=>{
|
|
5
|
+
if (currentBundleId === __WEBPACK_EXTERNAL_MODULE__hot_updater_core__.NIL_UUID) return false;
|
|
6
|
+
if (0 === bundles.length) return true;
|
|
7
|
+
const enabled = bundles.find((item)=>item.id === currentBundleId)?.enabled;
|
|
8
|
+
const availableOldVersion = bundles.find((item)=>item.id.localeCompare(currentBundleId) < 0 && item.enabled)?.enabled;
|
|
9
|
+
if (isNullable(enabled)) return Boolean(availableOldVersion);
|
|
10
|
+
return !enabled;
|
|
11
|
+
};
|
|
12
|
+
const semverSatisfies = (targetVersion, currentVersion)=>{
|
|
13
|
+
const currentCoerce = __WEBPACK_EXTERNAL_MODULE_semver__["default"].coerce(currentVersion);
|
|
14
|
+
if (!currentCoerce) throw new Error("Invalid current version");
|
|
15
|
+
return __WEBPACK_EXTERNAL_MODULE_semver__["default"].satisfies(currentCoerce.version, targetVersion);
|
|
16
|
+
};
|
|
17
|
+
const findLatestBundles = (bundles)=>bundles?.filter((item)=>item.enabled)?.sort((a, b)=>b.id.localeCompare(a.id))?.[0] ?? null;
|
|
18
|
+
const getUpdateInfo = async (bundles, { platform, bundleId, appVersion })=>{
|
|
19
|
+
const filteredBundles = bundles.filter((b)=>b.platform === platform && semverSatisfies(b.targetVersion, appVersion));
|
|
20
|
+
const isRollback = checkForRollback(filteredBundles, bundleId);
|
|
21
|
+
const latestBundle = await findLatestBundles(filteredBundles);
|
|
22
|
+
if (!latestBundle) {
|
|
23
|
+
if (isRollback) return {
|
|
24
|
+
id: __WEBPACK_EXTERNAL_MODULE__hot_updater_core__.NIL_UUID,
|
|
25
|
+
forceUpdate: true,
|
|
26
|
+
fileUrl: null,
|
|
27
|
+
fileHash: null,
|
|
28
|
+
status: "ROLLBACK"
|
|
29
|
+
};
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
if (latestBundle.fileUrl) {
|
|
33
|
+
if (isRollback) {
|
|
34
|
+
if (latestBundle.id === bundleId) return null;
|
|
35
|
+
if (latestBundle.id.localeCompare(bundleId) > 0) return {
|
|
36
|
+
id: latestBundle.id,
|
|
37
|
+
forceUpdate: latestBundle.forceUpdate,
|
|
38
|
+
fileUrl: latestBundle.fileUrl,
|
|
39
|
+
fileHash: latestBundle.fileHash,
|
|
40
|
+
status: "UPDATE"
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
id: latestBundle.id,
|
|
44
|
+
forceUpdate: true,
|
|
45
|
+
fileUrl: latestBundle.fileUrl,
|
|
46
|
+
fileHash: latestBundle.fileHash,
|
|
47
|
+
status: "ROLLBACK"
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (latestBundle.id.localeCompare(bundleId) > 0) return {
|
|
52
|
+
id: latestBundle.id,
|
|
53
|
+
forceUpdate: latestBundle.forceUpdate,
|
|
54
|
+
fileUrl: latestBundle.fileUrl,
|
|
55
|
+
fileHash: latestBundle.fileHash,
|
|
56
|
+
status: "UPDATE"
|
|
57
|
+
};
|
|
58
|
+
return null;
|
|
59
|
+
};
|
|
60
|
+
export { getUpdateInfo };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const semverSatisfies: (targetVersion: string, currentVersion: string) => boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isNullable: (value: unknown) => value is null | undefined;
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hot-updater/js",
|
|
3
|
+
"version": "0.1.6-0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "React Native OTA solution for self-hosted",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"main": "dist/index.cjs",
|
|
8
|
+
"module": "dist/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"package.json"
|
|
19
|
+
],
|
|
20
|
+
"keywords": [
|
|
21
|
+
"react-native",
|
|
22
|
+
"react-native-code-push",
|
|
23
|
+
"code-push",
|
|
24
|
+
"eas",
|
|
25
|
+
"eas-update",
|
|
26
|
+
"expo",
|
|
27
|
+
"expo-update",
|
|
28
|
+
"self-hosted"
|
|
29
|
+
],
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"repository": "https://github.com/gronxb/hot-updater",
|
|
32
|
+
"author": "gronxb <gron1gh1@gmail.com> (https://github.com/gronxb)",
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/gronxb/hot-updater/issues"
|
|
35
|
+
},
|
|
36
|
+
"homepage": "https://github.com/gronxb/hot-updater#readme",
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@hot-updater/core": "0.1.6-0",
|
|
42
|
+
"semver": "^7.6.3"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@rslib/core": "^0.2.2",
|
|
46
|
+
"@types/node": "^20.9.4",
|
|
47
|
+
"@types/semver": "^7.5.8"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "rslib build",
|
|
51
|
+
"test:type": "tsc --noEmit"
|
|
52
|
+
}
|
|
53
|
+
}
|