@hot-updater/react-native 1.0.0-rc.40 → 1.0.0-rc.41
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/lib/commonjs/appReady.js +25 -31
- package/lib/commonjs/appReady.js.map +1 -1
- package/lib/commonjs/checkForUpdate.js +9 -9
- package/lib/commonjs/checkForUpdate.js.map +1 -1
- package/lib/commonjs/error.js +1 -1
- package/lib/commonjs/httpClient.js +1 -1
- package/lib/commonjs/index.js +304 -326
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/init.types.js +6 -0
- package/lib/commonjs/init.types.js.map +1 -0
- package/lib/commonjs/native.js +3 -3
- package/lib/commonjs/pluginHost.js +11 -15
- package/lib/commonjs/pluginHost.js.map +1 -1
- package/lib/commonjs/sdkVersion.js +1 -1
- package/lib/commonjs/wrap.js +7 -16
- package/lib/commonjs/wrap.js.map +1 -1
- package/lib/module/appReady.js +23 -28
- package/lib/module/appReady.js.map +1 -1
- package/lib/module/checkForUpdate.js +10 -10
- package/lib/module/checkForUpdate.js.map +1 -1
- package/lib/module/clientPlugin.js.map +1 -1
- package/lib/module/error.js +1 -1
- package/lib/module/httpClient.js +1 -1
- package/lib/module/index.js +299 -329
- package/lib/module/index.js.map +1 -1
- package/lib/module/init.types.js +4 -0
- package/lib/module/init.types.js.map +1 -0
- package/lib/module/native.js +3 -3
- package/lib/module/pluginHost.js +9 -9
- package/lib/module/pluginHost.js.map +1 -1
- package/lib/module/sdkVersion.js +1 -1
- package/lib/module/wrap.js +7 -15
- package/lib/module/wrap.js.map +1 -1
- package/lib/typescript/commonjs/appReady.d.ts +18 -9
- package/lib/typescript/commonjs/appReady.d.ts.map +1 -1
- package/lib/typescript/commonjs/checkForUpdate.d.ts +5 -3
- package/lib/typescript/commonjs/checkForUpdate.d.ts.map +1 -1
- package/lib/typescript/commonjs/clientPlugin.d.ts +1 -1
- package/lib/typescript/commonjs/clientPlugin.d.ts.map +1 -1
- package/lib/typescript/commonjs/error.d.ts +1 -1
- package/lib/typescript/commonjs/httpClient.d.ts +1 -1
- package/lib/typescript/commonjs/httpClient.d.ts.map +1 -1
- package/lib/typescript/commonjs/index.d.ts +122 -110
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/init.types.d.ts +21 -0
- package/lib/typescript/commonjs/init.types.d.ts.map +1 -0
- package/lib/typescript/commonjs/native.d.ts +3 -3
- package/lib/typescript/commonjs/pluginHost.d.ts +7 -3
- package/lib/typescript/commonjs/pluginHost.d.ts.map +1 -1
- package/lib/typescript/commonjs/sdkVersion.d.ts +1 -1
- package/lib/typescript/commonjs/wrap.d.ts +2 -3
- package/lib/typescript/commonjs/wrap.d.ts.map +1 -1
- package/lib/typescript/commonjs/wrap.types.d.ts +13 -40
- package/lib/typescript/commonjs/wrap.types.d.ts.map +1 -1
- package/lib/typescript/module/appReady.d.ts +18 -9
- package/lib/typescript/module/appReady.d.ts.map +1 -1
- package/lib/typescript/module/checkForUpdate.d.ts +5 -3
- package/lib/typescript/module/checkForUpdate.d.ts.map +1 -1
- package/lib/typescript/module/clientPlugin.d.ts +1 -1
- package/lib/typescript/module/clientPlugin.d.ts.map +1 -1
- package/lib/typescript/module/error.d.ts +1 -1
- package/lib/typescript/module/httpClient.d.ts +1 -1
- package/lib/typescript/module/httpClient.d.ts.map +1 -1
- package/lib/typescript/module/index.d.ts +122 -110
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/init.types.d.ts +21 -0
- package/lib/typescript/module/init.types.d.ts.map +1 -0
- package/lib/typescript/module/native.d.ts +3 -3
- package/lib/typescript/module/pluginHost.d.ts +7 -3
- package/lib/typescript/module/pluginHost.d.ts.map +1 -1
- package/lib/typescript/module/sdkVersion.d.ts +1 -1
- package/lib/typescript/module/wrap.d.ts +2 -3
- package/lib/typescript/module/wrap.d.ts.map +1 -1
- package/lib/typescript/module/wrap.types.d.ts +13 -40
- package/lib/typescript/module/wrap.types.d.ts.map +1 -1
- package/package.json +4 -3
- package/src/appReady.ts +43 -37
- package/src/checkForUpdate.ts +19 -11
- package/src/clientPlugin.ts +3 -0
- package/src/error.ts +1 -1
- package/src/httpClient.ts +1 -1
- package/src/index.ts +344 -422
- package/src/init.types.ts +24 -0
- package/src/native.ts +3 -3
- package/src/pluginHost.ts +16 -11
- package/src/sdkVersion.ts +1 -1
- package/src/wrap.tsx +6 -20
- package/src/wrap.types.ts +18 -45
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { HotUpdaterClientPlugin } from "./clientPlugin";
|
|
2
|
+
import type { HotUpdaterError } from "./error";
|
|
3
|
+
import type { NotifyAppReadyResult } from "./native";
|
|
4
|
+
import type { HotUpdaterBaseURL } from "./types";
|
|
5
|
+
|
|
6
|
+
export interface HotUpdaterInitOptions<
|
|
7
|
+
TPlugins extends readonly HotUpdaterClientPlugin[] =
|
|
8
|
+
readonly HotUpdaterClientPlugin[],
|
|
9
|
+
> {
|
|
10
|
+
/**
|
|
11
|
+
* Client plugins, such as `insights()` and `remoteConfig()` from
|
|
12
|
+
* `@hot-updater/react-native`. Each plugin's `setup` runs once for the
|
|
13
|
+
* instance `init` returns; its hooks observe that instance's launch,
|
|
14
|
+
* update checks, downloads, and update failures, and its API is on the
|
|
15
|
+
* instance, under the plugin's id. Plugin ids must be unique.
|
|
16
|
+
*/
|
|
17
|
+
plugins?: TPlugins;
|
|
18
|
+
/** Base URL of a server exposing the Hot Updater v1 client HTTP protocol. */
|
|
19
|
+
baseURL: HotUpdaterBaseURL;
|
|
20
|
+
requestHeaders?: Record<string, string>;
|
|
21
|
+
requestTimeout?: number;
|
|
22
|
+
onNotifyAppReady?: (result: NotifyAppReadyResult) => void;
|
|
23
|
+
onError?: (error: HotUpdaterError | Error | unknown) => void;
|
|
24
|
+
}
|
package/src/native.ts
CHANGED
|
@@ -46,7 +46,7 @@ type ActiveBundleSnapshotCacheValues = {
|
|
|
46
46
|
type ActiveBundleSnapshotCacheKey = keyof ActiveBundleSnapshotCacheValues;
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
|
-
* Built-in reload behaviors used by `
|
|
49
|
+
* Built-in reload behaviors used by `hotUpdater.reload()`.
|
|
50
50
|
*
|
|
51
51
|
* - `reload`: In-process React Native reload.
|
|
52
52
|
* - `processRestart`: Android-only cold restart. On iOS the same call behaves like `reload`.
|
|
@@ -578,7 +578,7 @@ export const reload = async () => {
|
|
|
578
578
|
};
|
|
579
579
|
|
|
580
580
|
/**
|
|
581
|
-
* Configures how `
|
|
581
|
+
* Configures how `hotUpdater.reload()` should behave.
|
|
582
582
|
*
|
|
583
583
|
* This API is available on both Android and iOS so app code can stay symmetric.
|
|
584
584
|
* By default, HotUpdater uses `processRestart`.
|
|
@@ -959,7 +959,7 @@ export const readNotifyAppReady = (): {
|
|
|
959
959
|
*
|
|
960
960
|
* @example
|
|
961
961
|
* ```ts
|
|
962
|
-
* const result =
|
|
962
|
+
* const result = hotUpdater.notifyAppReady();
|
|
963
963
|
*
|
|
964
964
|
* if (result.status === "RECOVERED") {
|
|
965
965
|
* console.log(result.fromBundleId, result.toBundleId);
|
package/src/pluginHost.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
createPluginHost,
|
|
3
|
+
type PluginHost,
|
|
4
|
+
type PluginHostEnvironment,
|
|
5
|
+
} from "@hot-updater/protocol";
|
|
2
6
|
import { Platform } from "react-native";
|
|
3
7
|
|
|
4
8
|
import {
|
|
@@ -14,16 +18,10 @@ import {
|
|
|
14
18
|
} from "./native";
|
|
15
19
|
import { HOT_UPDATER_SDK_VERSION } from "./sdkVersion";
|
|
16
20
|
|
|
17
|
-
export type { PluginHostConfig } from "@hot-updater/protocol";
|
|
21
|
+
export type { PluginHost, PluginHostConfig } from "@hot-updater/protocol";
|
|
18
22
|
|
|
19
|
-
/** The
|
|
20
|
-
|
|
21
|
-
configurePlugins,
|
|
22
|
-
hasPluginHook,
|
|
23
|
-
buildPluginEvent,
|
|
24
|
-
dispatchPluginHook,
|
|
25
|
-
emitPluginHook,
|
|
26
|
-
} = createPluginHost({
|
|
23
|
+
/** The native module and runtime every plugin host reads. */
|
|
24
|
+
const environment: PluginHostEnvironment = {
|
|
27
25
|
fetch: (url, init) => fetch(url, init),
|
|
28
26
|
get platform() {
|
|
29
27
|
return Platform.OS === "android" ? "android" : "ios";
|
|
@@ -44,4 +42,11 @@ export const {
|
|
|
44
42
|
getStorageItem: (key) => getStorageItem(key),
|
|
45
43
|
setStorageItem: (key, value) => setStorageItem(key, value),
|
|
46
44
|
now: () => Date.now(),
|
|
47
|
-
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Creates an instance's plugin host: its plugins read the native module and
|
|
49
|
+
* fetch the server the instance was configured with.
|
|
50
|
+
*/
|
|
51
|
+
export const createAppPluginHost = (): PluginHost =>
|
|
52
|
+
createPluginHost(environment);
|
package/src/sdkVersion.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const HOT_UPDATER_SDK_VERSION = "1.0.0-rc.
|
|
1
|
+
export const HOT_UPDATER_SDK_VERSION = "1.0.0-rc.41";
|
package/src/wrap.tsx
CHANGED
|
@@ -1,31 +1,21 @@
|
|
|
1
1
|
import React, { useEffect, useState } from "react";
|
|
2
2
|
|
|
3
|
-
import { handleNotifyAppReady } from "./appReady";
|
|
4
|
-
import { checkForUpdate } from "./checkForUpdate";
|
|
5
3
|
import { useEventCallback } from "./hooks/useEventCallback";
|
|
6
4
|
import { getUpdateId, reload } from "./native";
|
|
7
5
|
import { useHotUpdaterStore } from "./store";
|
|
8
6
|
import type {
|
|
9
7
|
HotUpdaterFallbackComponentProps,
|
|
10
|
-
InternalInitOptions,
|
|
11
8
|
InternalWrapOptions,
|
|
12
9
|
UpdateStatus,
|
|
13
10
|
} from "./wrap.types";
|
|
14
11
|
|
|
15
12
|
export type {
|
|
16
|
-
AutoUpdateOptions,
|
|
17
13
|
HotUpdaterFallbackComponentProps,
|
|
18
|
-
|
|
19
|
-
HotUpdaterOptions,
|
|
20
|
-
InternalInitOptions,
|
|
14
|
+
HotUpdaterWrapOptions,
|
|
21
15
|
InternalWrapOptions,
|
|
22
16
|
RunUpdateProcessResponse,
|
|
23
17
|
} from "./wrap.types";
|
|
24
18
|
|
|
25
|
-
export function init(options: InternalInitOptions): void {
|
|
26
|
-
void handleNotifyAppReady(options);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
19
|
export function wrap(
|
|
30
20
|
options: InternalWrapOptions,
|
|
31
21
|
): <P extends object>(
|
|
@@ -81,16 +71,12 @@ export function wrap(
|
|
|
81
71
|
try {
|
|
82
72
|
setUpdateStatus("CHECK_FOR_UPDATE");
|
|
83
73
|
|
|
84
|
-
const
|
|
85
|
-
const updateInfo = await checkForUpdate({
|
|
86
|
-
client: restOptions.client,
|
|
74
|
+
const updateInfo = await restOptions.checkForUpdate({
|
|
87
75
|
updateStrategy: restOptions.updateStrategy,
|
|
88
|
-
requestHeaders: restOptions.requestHeaders,
|
|
89
|
-
requestTimeout: restOptions.requestTimeout,
|
|
90
|
-
onError: restOptions.onError,
|
|
91
76
|
});
|
|
92
77
|
|
|
93
|
-
|
|
78
|
+
// A forced update reloads only after init has read this launch.
|
|
79
|
+
await restOptions.appReady();
|
|
94
80
|
setMessage(updateInfo?.message ?? null);
|
|
95
81
|
|
|
96
82
|
if (!updateInfo) {
|
|
@@ -106,7 +92,7 @@ export function wrap(
|
|
|
106
92
|
|
|
107
93
|
if (updateInfo.shouldForceUpdate === false) {
|
|
108
94
|
void updateInfo.updateBundle().catch((error: unknown) => {
|
|
109
|
-
restOptions.onError
|
|
95
|
+
restOptions.onError(error);
|
|
110
96
|
});
|
|
111
97
|
|
|
112
98
|
restOptions.onUpdateProcessCompleted?.({
|
|
@@ -143,7 +129,7 @@ export function wrap(
|
|
|
143
129
|
} catch (error) {
|
|
144
130
|
const normalizedError =
|
|
145
131
|
error instanceof Error ? error : new Error(String(error));
|
|
146
|
-
restOptions.onError
|
|
132
|
+
restOptions.onError(normalizedError);
|
|
147
133
|
setUpdateStatus("UPDATE_PROCESS_COMPLETED");
|
|
148
134
|
}
|
|
149
135
|
});
|
package/src/wrap.types.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import type React from "react";
|
|
2
2
|
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import type {
|
|
4
|
+
CheckForUpdateOptions,
|
|
5
|
+
CheckForUpdateResult,
|
|
6
|
+
} from "./checkForUpdate";
|
|
7
7
|
import type { HotUpdaterState } from "./store";
|
|
8
|
-
import type { HotUpdaterBaseURL } from "./types";
|
|
9
8
|
|
|
10
9
|
export interface RunUpdateProcessResponse {
|
|
11
10
|
status: "ROLLBACK" | "UPDATE" | "UP_TO_DATE";
|
|
@@ -27,50 +26,24 @@ export type HotUpdaterFallbackComponentProps = {
|
|
|
27
26
|
details: HotUpdaterState["details"];
|
|
28
27
|
};
|
|
29
28
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
* update failures. Plugin ids must be unique.
|
|
36
|
-
*/
|
|
37
|
-
plugins?: readonly HotUpdaterClientPlugin[];
|
|
38
|
-
/** Base URL of a server exposing the Hot Updater v1 client HTTP protocol. */
|
|
39
|
-
baseURL: HotUpdaterBaseURL;
|
|
40
|
-
requestHeaders?: Record<string, string>;
|
|
41
|
-
requestTimeout?: number;
|
|
42
|
-
onNotifyAppReady?: (result: NotifyAppReadyResult) => void;
|
|
43
|
-
onError?: (error: HotUpdaterError | Error | unknown) => void;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export type AutoUpdateOptions = CommonHotUpdaterOptions & {
|
|
29
|
+
/**
|
|
30
|
+
* The update flow `hotUpdater.wrap` runs when the wrapped root mounts. The
|
|
31
|
+
* server, request settings, and plugins come from `HotUpdater.init`.
|
|
32
|
+
*/
|
|
33
|
+
export interface HotUpdaterWrapOptions {
|
|
47
34
|
updateStrategy: "fingerprint" | "appVersion";
|
|
48
35
|
fallbackComponent?: React.FC<HotUpdaterFallbackComponentProps>;
|
|
49
36
|
onProgress?: (progress: number) => void;
|
|
50
37
|
reloadOnForceUpdate?: boolean;
|
|
51
38
|
onUpdateProcessCompleted?: (response: RunUpdateProcessResponse) => void;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export type HotUpdaterInitOptions = CommonHotUpdaterOptions;
|
|
55
|
-
|
|
56
|
-
export type HotUpdaterOptions = AutoUpdateOptions;
|
|
39
|
+
}
|
|
57
40
|
|
|
58
|
-
type
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
41
|
+
export type InternalWrapOptions = HotUpdaterWrapOptions & {
|
|
42
|
+
/** The instance's check, over the configuration of `HotUpdater.init`. */
|
|
43
|
+
checkForUpdate: (
|
|
44
|
+
options: Pick<CheckForUpdateOptions, "updateStrategy">,
|
|
45
|
+
) => Promise<CheckForUpdateResult | null>;
|
|
46
|
+
/** Settles once `HotUpdater.init` has read this launch. */
|
|
47
|
+
appReady: () => Promise<unknown>;
|
|
48
|
+
onError: (error: unknown) => void;
|
|
64
49
|
};
|
|
65
|
-
|
|
66
|
-
type InternalAutoUpdateOptions = InternalCommonOptions & {
|
|
67
|
-
updateStrategy: "fingerprint" | "appVersion";
|
|
68
|
-
fallbackComponent?: React.FC<HotUpdaterFallbackComponentProps>;
|
|
69
|
-
onProgress?: (progress: number) => void;
|
|
70
|
-
reloadOnForceUpdate?: boolean;
|
|
71
|
-
onUpdateProcessCompleted?: (response: RunUpdateProcessResponse) => void;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
export type InternalInitOptions = InternalCommonOptions;
|
|
75
|
-
|
|
76
|
-
export type InternalWrapOptions = InternalAutoUpdateOptions;
|