@hot-updater/react-native 0.1.6-0 → 0.2.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/dist/ensureBundles.d.ts +2 -0
- package/dist/error.d.ts +3 -0
- package/dist/index.d.ts +8 -62
- package/dist/index.js +3137 -4285
- package/dist/index.js.LICENSE.txt +19 -0
- package/dist/index.mjs +3103 -4278
- package/dist/index.mjs.LICENSE.txt +19 -0
- package/dist/init.d.ts +10 -0
- package/dist/native.d.ts +29 -0
- package/dist/store.d.ts +9 -0
- package/package.json +4 -4
- package/src/ensureBundles.ts +19 -4
- package/src/init.tsx +29 -10
- package/LICENSE +0 -21
- package/dist/index.d.mts +0 -71
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license React
|
|
3
|
+
* react.development.js
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @license React
|
|
13
|
+
* react.production.min.js
|
|
14
|
+
*
|
|
15
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
16
|
+
*
|
|
17
|
+
* This source code is licensed under the MIT license found in the
|
|
18
|
+
* LICENSE file in the root directory of this source tree.
|
|
19
|
+
*/
|
package/dist/init.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { BundleArg } from "@hot-updater/core";
|
|
2
|
+
import { HotUpdaterError } from "./error";
|
|
3
|
+
export type HotUpdaterStatus = "INSTALLING_UPDATE" | "UP_TO_DATE";
|
|
4
|
+
export interface HotUpdaterInitConfig {
|
|
5
|
+
source: BundleArg;
|
|
6
|
+
requestHeaders?: Record<string, string>;
|
|
7
|
+
onSuccess?: (status: HotUpdaterStatus) => void;
|
|
8
|
+
onError?: (error: HotUpdaterError) => void;
|
|
9
|
+
}
|
|
10
|
+
export declare const init: (config: HotUpdaterInitConfig) => Promise<void>;
|
package/dist/native.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export type HotUpdaterEvent = {
|
|
2
|
+
onProgress: {
|
|
3
|
+
progress: number;
|
|
4
|
+
};
|
|
5
|
+
};
|
|
6
|
+
export declare const addListener: <T extends keyof HotUpdaterEvent>(eventName: T, listener: (event: HotUpdaterEvent[T]) => void) => void;
|
|
7
|
+
/**
|
|
8
|
+
* Fetches the current bundle version id.
|
|
9
|
+
*
|
|
10
|
+
* @async
|
|
11
|
+
* @returns {Promise<string>} Resolves with the current version id or null if not available.
|
|
12
|
+
*/
|
|
13
|
+
export declare const getBundleId: () => string;
|
|
14
|
+
/**
|
|
15
|
+
* Downloads files from given URLs.
|
|
16
|
+
*
|
|
17
|
+
* @param {string} bundleId - identifier for the bundle version.
|
|
18
|
+
* @param {string | null} zipUrl - zip file URL.
|
|
19
|
+
* @returns {Promise<boolean>} Resolves with true if download was successful, otherwise rejects with an error.
|
|
20
|
+
*/
|
|
21
|
+
export declare const updateBundle: (bundleId: string, zipUrl: string | null) => Promise<boolean>;
|
|
22
|
+
/**
|
|
23
|
+
* Fetches the current app version.
|
|
24
|
+
*/
|
|
25
|
+
export declare const getAppVersion: () => Promise<string | null>;
|
|
26
|
+
/**
|
|
27
|
+
* Reloads the app.
|
|
28
|
+
*/
|
|
29
|
+
export declare const reload: () => void;
|
package/dist/store.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type HotUpdaterState = {
|
|
2
|
+
progress: number;
|
|
3
|
+
};
|
|
4
|
+
export declare const hotUpdaterStore: {
|
|
5
|
+
getState: () => HotUpdaterState;
|
|
6
|
+
setState: (newState: Partial<HotUpdaterState>) => void;
|
|
7
|
+
subscribe: (listener: () => void) => () => boolean;
|
|
8
|
+
};
|
|
9
|
+
export declare const useHotUpdaterStore: () => HotUpdaterState;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/react-native",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "React Native OTA solution for self-hosted",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -73,13 +73,13 @@
|
|
|
73
73
|
"react": "18.3.1",
|
|
74
74
|
"react-native": "0.76.2",
|
|
75
75
|
"react-native-builder-bob": "^0.33.1",
|
|
76
|
-
"@hot-updater/js": "0.
|
|
76
|
+
"@hot-updater/js": "0.2.0"
|
|
77
77
|
},
|
|
78
78
|
"dependencies": {
|
|
79
|
-
"@hot-updater/core": "0.
|
|
79
|
+
"@hot-updater/core": "0.2.0"
|
|
80
80
|
},
|
|
81
81
|
"scripts": {
|
|
82
|
-
"build": "
|
|
82
|
+
"build": "rslib build",
|
|
83
83
|
"test:type": "tsc --noEmit",
|
|
84
84
|
"test": "vitest",
|
|
85
85
|
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib"
|
package/src/ensureBundles.ts
CHANGED
|
@@ -1,12 +1,27 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
Bundle,
|
|
3
|
+
BundleArg,
|
|
4
|
+
GetBundlesArgs,
|
|
5
|
+
UpdateInfo,
|
|
6
|
+
} from "@hot-updater/core";
|
|
2
7
|
|
|
3
|
-
export const ensureBundles = async (
|
|
8
|
+
export const ensureBundles = async (
|
|
9
|
+
bundle: BundleArg,
|
|
10
|
+
{ appVersion, bundleId, platform }: GetBundlesArgs,
|
|
11
|
+
requestHeaders?: Record<string, string>,
|
|
12
|
+
): Promise<Bundle[] | UpdateInfo> => {
|
|
4
13
|
try {
|
|
5
14
|
let bundles: Bundle[] | null = null;
|
|
6
15
|
if (typeof bundle === "string") {
|
|
7
16
|
if (bundle.startsWith("http")) {
|
|
8
|
-
|
|
9
|
-
|
|
17
|
+
return await fetch(bundle, {
|
|
18
|
+
headers: {
|
|
19
|
+
"x-app-platform": platform,
|
|
20
|
+
"x-app-version": appVersion,
|
|
21
|
+
"x-bundle-id": bundleId,
|
|
22
|
+
...requestHeaders,
|
|
23
|
+
},
|
|
24
|
+
}).then((res) => res.json());
|
|
10
25
|
}
|
|
11
26
|
} else if (typeof bundle === "function") {
|
|
12
27
|
bundles = await bundle();
|
package/src/init.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BundleArg } from "@hot-updater/core";
|
|
1
|
+
import type { BundleArg, UpdateInfo } from "@hot-updater/core";
|
|
2
2
|
import { getUpdateInfo } from "@hot-updater/js";
|
|
3
3
|
import { Platform } from "react-native";
|
|
4
4
|
import { ensureBundles } from "./ensureBundles";
|
|
@@ -9,6 +9,7 @@ export type HotUpdaterStatus = "INSTALLING_UPDATE" | "UP_TO_DATE";
|
|
|
9
9
|
|
|
10
10
|
export interface HotUpdaterInitConfig {
|
|
11
11
|
source: BundleArg;
|
|
12
|
+
requestHeaders?: Record<string, string>;
|
|
12
13
|
onSuccess?: (status: HotUpdaterStatus) => void;
|
|
13
14
|
onError?: (error: HotUpdaterError) => void;
|
|
14
15
|
}
|
|
@@ -40,22 +41,40 @@ export const init = async (config: HotUpdaterInitConfig) => {
|
|
|
40
41
|
throw error;
|
|
41
42
|
}
|
|
42
43
|
|
|
43
|
-
const bundles = await ensureBundles(
|
|
44
|
+
const bundles = await ensureBundles(
|
|
45
|
+
config.source,
|
|
46
|
+
{
|
|
47
|
+
appVersion: currentAppVersion,
|
|
48
|
+
bundleId: currentBundleId,
|
|
49
|
+
platform,
|
|
50
|
+
},
|
|
51
|
+
config.requestHeaders,
|
|
52
|
+
);
|
|
44
53
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
54
|
+
let updateInfo: UpdateInfo | null = null;
|
|
55
|
+
if (Array.isArray(bundles)) {
|
|
56
|
+
// Direct comparison
|
|
57
|
+
updateInfo = await getUpdateInfo(bundles, {
|
|
58
|
+
appVersion: currentAppVersion,
|
|
59
|
+
bundleId: currentBundleId,
|
|
60
|
+
platform,
|
|
61
|
+
});
|
|
62
|
+
} else {
|
|
63
|
+
// Already verified from server
|
|
64
|
+
updateInfo = bundles;
|
|
65
|
+
}
|
|
50
66
|
|
|
51
|
-
if (!
|
|
67
|
+
if (!updateInfo) {
|
|
52
68
|
config?.onSuccess?.("UP_TO_DATE");
|
|
53
69
|
return;
|
|
54
70
|
}
|
|
55
71
|
|
|
56
72
|
try {
|
|
57
|
-
const isSuccess = await updateBundle(
|
|
58
|
-
|
|
73
|
+
const isSuccess = await updateBundle(
|
|
74
|
+
updateInfo.id,
|
|
75
|
+
updateInfo.fileUrl || "",
|
|
76
|
+
);
|
|
77
|
+
if (isSuccess && updateInfo.forceUpdate) {
|
|
59
78
|
reload();
|
|
60
79
|
|
|
61
80
|
config?.onSuccess?.("INSTALLING_UPDATE");
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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.
|
package/dist/index.d.mts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import * as _hot_updater_core from '@hot-updater/core';
|
|
2
|
-
import { BundleArg } from '@hot-updater/core';
|
|
3
|
-
|
|
4
|
-
type HotUpdaterEvent = {
|
|
5
|
-
onProgress: {
|
|
6
|
-
progress: number;
|
|
7
|
-
};
|
|
8
|
-
};
|
|
9
|
-
declare const addListener: <T extends keyof HotUpdaterEvent>(eventName: T, listener: (event: HotUpdaterEvent[T]) => void) => void;
|
|
10
|
-
/**
|
|
11
|
-
* Fetches the current bundle version id.
|
|
12
|
-
*
|
|
13
|
-
* @async
|
|
14
|
-
* @returns {Promise<string>} Resolves with the current version id or null if not available.
|
|
15
|
-
*/
|
|
16
|
-
declare const getBundleId: () => string;
|
|
17
|
-
/**
|
|
18
|
-
* Downloads files from given URLs.
|
|
19
|
-
*
|
|
20
|
-
* @param {string} bundleId - identifier for the bundle version.
|
|
21
|
-
* @param {string | null} zipUrl - zip file URL.
|
|
22
|
-
* @returns {Promise<boolean>} Resolves with true if download was successful, otherwise rejects with an error.
|
|
23
|
-
*/
|
|
24
|
-
declare const updateBundle: (bundleId: string, zipUrl: string | null) => Promise<boolean>;
|
|
25
|
-
/**
|
|
26
|
-
* Fetches the current app version.
|
|
27
|
-
*/
|
|
28
|
-
declare const getAppVersion: () => Promise<string | null>;
|
|
29
|
-
/**
|
|
30
|
-
* Reloads the app.
|
|
31
|
-
*/
|
|
32
|
-
declare const reload: () => void;
|
|
33
|
-
|
|
34
|
-
declare class HotUpdaterError extends Error {
|
|
35
|
-
constructor(message: string);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
type HotUpdaterStatus = "INSTALLING_UPDATE" | "UP_TO_DATE";
|
|
39
|
-
interface HotUpdaterInitConfig {
|
|
40
|
-
source: BundleArg;
|
|
41
|
-
onSuccess?: (status: HotUpdaterStatus) => void;
|
|
42
|
-
onError?: (error: HotUpdaterError) => void;
|
|
43
|
-
}
|
|
44
|
-
declare const init: (config: HotUpdaterInitConfig) => Promise<void>;
|
|
45
|
-
|
|
46
|
-
type HotUpdaterState = {
|
|
47
|
-
progress: number;
|
|
48
|
-
};
|
|
49
|
-
declare const hotUpdaterStore: {
|
|
50
|
-
getState: () => HotUpdaterState;
|
|
51
|
-
setState: (newState: Partial<HotUpdaterState>) => void;
|
|
52
|
-
subscribe: (listener: () => void) => () => boolean;
|
|
53
|
-
};
|
|
54
|
-
declare const useHotUpdaterStore: () => HotUpdaterState;
|
|
55
|
-
|
|
56
|
-
declare const HotUpdater: {
|
|
57
|
-
init: (config: HotUpdaterInitConfig) => Promise<void>;
|
|
58
|
-
reload: () => void;
|
|
59
|
-
getAppVersion: () => Promise<string | null>;
|
|
60
|
-
getBundleId: () => string;
|
|
61
|
-
addListener: <T extends keyof HotUpdaterEvent>(eventName: T, listener: (event: HotUpdaterEvent[T]) => void) => void;
|
|
62
|
-
ensureBundles: (bundle: _hot_updater_core.BundleArg) => Promise<_hot_updater_core.Bundle[]>;
|
|
63
|
-
updateBundle: (bundleId: string, zipUrl: string | null) => Promise<boolean>;
|
|
64
|
-
getUpdateInfo: (bundles: _hot_updater_core.Bundle[], { platform, bundleId, appVersion }: _hot_updater_core.GetBundlesArgs) => Promise<_hot_updater_core.UpdateInfo | null>;
|
|
65
|
-
/**
|
|
66
|
-
* In production environment, this value will be replaced with a uuidv7.
|
|
67
|
-
*/
|
|
68
|
-
HOT_UPDATER_BUNDLE_ID: string;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
export { HotUpdater, type HotUpdaterEvent, type HotUpdaterInitConfig, type HotUpdaterState, type HotUpdaterStatus, addListener, getAppVersion, getBundleId, hotUpdaterStore, init, reload, updateBundle, useHotUpdaterStore };
|