@hot-updater/react-native 0.16.0 → 0.16.1

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.
@@ -2,5 +2,10 @@ export interface CheckForUpdateOptions {
2
2
  source: string;
3
3
  requestHeaders?: Record<string, string>;
4
4
  onError?: (error: Error) => void;
5
+ /**
6
+ * The timeout duration for the request.
7
+ * @default 5000
8
+ */
9
+ requestTimeout?: number;
5
10
  }
6
11
  export declare function checkForUpdate(options: CheckForUpdateOptions): Promise<import("@hot-updater/core").AppUpdateInfo | null>;
@@ -1,2 +1,2 @@
1
1
  import type { AppUpdateInfo, GetBundlesArgs } from "@hot-updater/core";
2
- export declare const fetchUpdateInfo: (source: string, { appVersion, bundleId, platform, minBundleId, channel }: GetBundlesArgs, requestHeaders?: Record<string, string>, onError?: (error: Error) => void) => Promise<AppUpdateInfo | null>;
2
+ export declare const fetchUpdateInfo: (source: string, { appVersion, bundleId, platform, minBundleId, channel }: GetBundlesArgs, requestHeaders?: Record<string, string>, onError?: (error: Error) => void, requestTimeout?: number) => Promise<AppUpdateInfo | null>;
package/dist/index.js CHANGED
@@ -66,9 +66,14 @@ var __webpack_exports__ = {};
66
66
  this.name = "HotUpdaterError";
67
67
  }
68
68
  }
69
- const fetchUpdateInfo = async (source, { appVersion, bundleId, platform, minBundleId, channel }, requestHeaders, onError)=>{
69
+ const fetchUpdateInfo = async (source, { appVersion, bundleId, platform, minBundleId, channel }, requestHeaders, onError, requestTimeout = 5000)=>{
70
+ const controller = new AbortController();
71
+ const timeoutId = setTimeout(()=>{
72
+ controller.abort();
73
+ }, requestTimeout);
70
74
  try {
71
75
  const response = await fetch(source, {
76
+ signal: controller.signal,
72
77
  headers: {
73
78
  "Content-Type": "application/json",
74
79
  "x-app-platform": platform,
@@ -83,9 +88,14 @@ var __webpack_exports__ = {};
83
88
  ...requestHeaders
84
89
  }
85
90
  });
91
+ clearTimeout(timeoutId);
86
92
  if (200 !== response.status) throw new Error(response.statusText);
87
93
  return response.json();
88
94
  } catch (error) {
95
+ if ("AbortError" === error.name) {
96
+ onError?.(new Error("Request timed out"));
97
+ return null;
98
+ }
89
99
  onError?.(error);
90
100
  return null;
91
101
  }
@@ -157,7 +167,7 @@ var __webpack_exports__ = {};
157
167
  platform,
158
168
  minBundleId,
159
169
  channel: channel ?? void 0
160
- }, options.requestHeaders, options.onError);
170
+ }, options.requestHeaders, options.onError, options.requestTimeout);
161
171
  }
162
172
  const runUpdateProcess = async ({ reloadOnForceUpdate = true, ...checkForUpdateOptions })=>{
163
173
  const updateInfo = await checkForUpdate(checkForUpdateOptions);
package/dist/index.mjs CHANGED
@@ -41,9 +41,14 @@ class HotUpdaterError extends Error {
41
41
  this.name = "HotUpdaterError";
42
42
  }
43
43
  }
44
- const fetchUpdateInfo = async (source, { appVersion, bundleId, platform, minBundleId, channel }, requestHeaders, onError)=>{
44
+ const fetchUpdateInfo = async (source, { appVersion, bundleId, platform, minBundleId, channel }, requestHeaders, onError, requestTimeout = 5000)=>{
45
+ const controller = new AbortController();
46
+ const timeoutId = setTimeout(()=>{
47
+ controller.abort();
48
+ }, requestTimeout);
45
49
  try {
46
50
  const response = await fetch(source, {
51
+ signal: controller.signal,
47
52
  headers: {
48
53
  "Content-Type": "application/json",
49
54
  "x-app-platform": platform,
@@ -58,9 +63,14 @@ const fetchUpdateInfo = async (source, { appVersion, bundleId, platform, minBund
58
63
  ...requestHeaders
59
64
  }
60
65
  });
66
+ clearTimeout(timeoutId);
61
67
  if (200 !== response.status) throw new Error(response.statusText);
62
68
  return response.json();
63
69
  } catch (error) {
70
+ if ("AbortError" === error.name) {
71
+ onError?.(new Error("Request timed out"));
72
+ return null;
73
+ }
64
74
  onError?.(error);
65
75
  return null;
66
76
  }
@@ -132,7 +142,7 @@ async function checkForUpdate(options) {
132
142
  platform,
133
143
  minBundleId,
134
144
  channel: channel ?? void 0
135
- }, options.requestHeaders, options.onError);
145
+ }, options.requestHeaders, options.onError, options.requestTimeout);
136
146
  }
137
147
  const runUpdateProcess = async ({ reloadOnForceUpdate = true, ...checkForUpdateOptions })=>{
138
148
  const updateInfo = await checkForUpdate(checkForUpdateOptions);
@@ -32,7 +32,7 @@ RCT_EXPORT_MODULE();
32
32
  uuid = @"00000000-0000-0000-0000-000000000000";
33
33
  return;
34
34
  #else
35
- // __DATE__, __TIME__ 컴파일 타임 값입니다.
35
+ // __DATE__, __TIME__ is compile-time
36
36
  NSString *compileDateStr = [NSString stringWithFormat:@"%s %s", __DATE__, __TIME__];
37
37
  NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
38
38
  [formatter setDateFormat:@"MMM d yyyy HH:mm:ss"];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hot-updater/react-native",
3
- "version": "0.16.0",
3
+ "version": "0.16.1",
4
4
  "description": "React Native OTA solution for self-hosted",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -81,8 +81,8 @@
81
81
  },
82
82
  "dependencies": {
83
83
  "use-sync-external-store": "1.4.0",
84
- "@hot-updater/js": "0.16.0",
85
- "@hot-updater/core": "0.16.0"
84
+ "@hot-updater/js": "0.16.1",
85
+ "@hot-updater/core": "0.16.1"
86
86
  },
87
87
  "scripts": {
88
88
  "build": "rslib build",
@@ -12,6 +12,11 @@ export interface CheckForUpdateOptions {
12
12
  source: string;
13
13
  requestHeaders?: Record<string, string>;
14
14
  onError?: (error: Error) => void;
15
+ /**
16
+ * The timeout duration for the request.
17
+ * @default 5000
18
+ */
19
+ requestTimeout?: number;
15
20
  }
16
21
 
17
22
  export async function checkForUpdate(options: CheckForUpdateOptions) {
@@ -48,5 +53,6 @@ export async function checkForUpdate(options: CheckForUpdateOptions) {
48
53
  },
49
54
  options.requestHeaders,
50
55
  options.onError,
56
+ options.requestTimeout,
51
57
  );
52
58
  }
@@ -5,12 +5,18 @@ export const fetchUpdateInfo = async (
5
5
  { appVersion, bundleId, platform, minBundleId, channel }: GetBundlesArgs,
6
6
  requestHeaders?: Record<string, string>,
7
7
  onError?: (error: Error) => void,
8
+ requestTimeout = 5000,
8
9
  ): Promise<AppUpdateInfo | null> => {
10
+ const controller = new AbortController();
11
+ const timeoutId = setTimeout(() => {
12
+ controller.abort();
13
+ }, requestTimeout);
14
+
9
15
  try {
10
16
  const response = await fetch(source, {
17
+ signal: controller.signal,
11
18
  headers: {
12
19
  "Content-Type": "application/json",
13
-
14
20
  "x-app-platform": platform,
15
21
  "x-app-version": appVersion,
16
22
  "x-bundle-id": bundleId,
@@ -20,11 +26,17 @@ export const fetchUpdateInfo = async (
20
26
  },
21
27
  });
22
28
 
29
+ clearTimeout(timeoutId);
30
+
23
31
  if (response.status !== 200) {
24
32
  throw new Error(response.statusText);
25
33
  }
26
34
  return response.json();
27
- } catch (error) {
35
+ } catch (error: any) {
36
+ if (error.name === "AbortError") {
37
+ onError?.(new Error("Request timed out"));
38
+ return null;
39
+ }
28
40
  onError?.(error as Error);
29
41
  return null;
30
42
  }