react-native-update 10.48.2 → 10.48.3
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/README-CN.md +40 -4
- package/README.md +40 -4
- package/android/src/main/java/cn/reactnative/modules/update/UpdateEventEmitter.java +13 -4
- package/biome.json +59 -0
- package/harmony/pushy/src/main/ets/DownloadTask.ts +2 -2
- package/harmony/pushy.har +0 -0
- package/package.json +5 -6
- package/src/NativePushy.ts +1 -1
- package/src/client.ts +62 -54
- package/src/context.ts +7 -7
- package/src/core.ts +51 -51
- package/src/endpoint.ts +7 -7
- package/src/error.ts +3 -3
- package/src/i18n.ts +2 -2
- package/src/index.ts +4 -4
- package/src/isInRollout.ts +10 -1
- package/src/provider.tsx +46 -56
- package/src/resolveCheckResult.ts +1 -1
- package/src/telemetry.ts +1 -1
- package/src/type.ts +2 -2
- package/src/utils.ts +30 -30
- package/.eslintrc.js +0 -4
- package/.prettierrc.js +0 -6
package/src/utils.ts
CHANGED
|
@@ -28,7 +28,7 @@ export function promiseAny<T>(promises: Promise<T>[]) {
|
|
|
28
28
|
}
|
|
29
29
|
let count = 0;
|
|
30
30
|
|
|
31
|
-
promises.forEach(promise => {
|
|
31
|
+
promises.forEach((promise) => {
|
|
32
32
|
Promise.resolve(promise)
|
|
33
33
|
.then(resolve)
|
|
34
34
|
.catch(() => {
|
|
@@ -44,25 +44,26 @@ export function promiseAny<T>(promises: Promise<T>[]) {
|
|
|
44
44
|
export const emptyObj = {};
|
|
45
45
|
export const noop = () => {};
|
|
46
46
|
const emptyModuleTarget: Record<string, typeof noop> = {};
|
|
47
|
-
export const emptyModule = new Proxy(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
get(_target, _prop) {
|
|
51
|
-
return noop;
|
|
52
|
-
},
|
|
47
|
+
export const emptyModule = new Proxy(emptyModuleTarget, {
|
|
48
|
+
get(_target, _prop) {
|
|
49
|
+
return noop;
|
|
53
50
|
},
|
|
54
|
-
);
|
|
51
|
+
});
|
|
55
52
|
|
|
56
53
|
const ping = isWeb
|
|
57
54
|
? Promise.resolve
|
|
58
55
|
: async (url: string) => {
|
|
59
56
|
try {
|
|
60
|
-
const {
|
|
57
|
+
const {
|
|
58
|
+
status,
|
|
59
|
+
statusText,
|
|
60
|
+
url: finalUrl,
|
|
61
|
+
} = await fetchWithTimeout(
|
|
61
62
|
url,
|
|
62
63
|
{
|
|
63
64
|
method: 'HEAD',
|
|
64
65
|
},
|
|
65
|
-
DEFAULT_FETCH_TIMEOUT_MS
|
|
66
|
+
DEFAULT_FETCH_TIMEOUT_MS
|
|
66
67
|
);
|
|
67
68
|
if (status === 200) {
|
|
68
69
|
return finalUrl;
|
|
@@ -77,7 +78,7 @@ const ping = isWeb
|
|
|
77
78
|
|
|
78
79
|
export function joinUrls(paths: string[], fileName?: string) {
|
|
79
80
|
if (fileName) {
|
|
80
|
-
return paths.map(path => {
|
|
81
|
+
return paths.map((path) => {
|
|
81
82
|
const normalizedPath = path.replace(/\/+$/, '');
|
|
82
83
|
// Keep explicit http(s) URLs for local/self-hosted update sources.
|
|
83
84
|
const baseUrl = /^[a-z][a-z0-9+.-]*:\/\//i.test(normalizedPath)
|
|
@@ -120,7 +121,7 @@ export const computeProgress = (received: number, total: number): number =>
|
|
|
120
121
|
export const fetchWithTimeout = (
|
|
121
122
|
url: string,
|
|
122
123
|
params: Parameters<typeof fetch>[1],
|
|
123
|
-
timeoutMs = DEFAULT_FETCH_TIMEOUT_MS
|
|
124
|
+
timeoutMs = DEFAULT_FETCH_TIMEOUT_MS
|
|
124
125
|
): Promise<Response> => {
|
|
125
126
|
// AbortController landed in the RN fetch polyfill around 0.60; we support
|
|
126
127
|
// older peers, so fall back to a plain timer race when it is unavailable
|
|
@@ -151,7 +152,7 @@ export const fetchWithTimeout = (
|
|
|
151
152
|
controller.abort();
|
|
152
153
|
}, timeoutMs);
|
|
153
154
|
|
|
154
|
-
return enhancedFetch(url, { ...params, signal: controller.signal })
|
|
155
|
+
return enhancedFetch(url, { ...params, signal: controller.signal as any })
|
|
155
156
|
.catch((e: any) => {
|
|
156
157
|
if (controller.signal.aborted) {
|
|
157
158
|
throw Error(i18n.t('error_ping_timeout'));
|
|
@@ -171,22 +172,21 @@ const isIdempotentRequest = (params: Parameters<typeof fetch>[1]) => {
|
|
|
171
172
|
export const enhancedFetch = async (
|
|
172
173
|
url: string,
|
|
173
174
|
params: Parameters<typeof fetch>[1],
|
|
174
|
-
isRetry = false
|
|
175
|
+
isRetry = false
|
|
175
176
|
): Promise<Response> => {
|
|
176
|
-
return fetch(url, params)
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
});
|
|
177
|
+
return fetch(url, params).catch((e) => {
|
|
178
|
+
log('fetch error', url, e);
|
|
179
|
+
if (
|
|
180
|
+
isRetry ||
|
|
181
|
+
(params as any)?.signal?.aborted ||
|
|
182
|
+
!url.startsWith('https:') ||
|
|
183
|
+
// Never replay non-idempotent requests (e.g. the checkUpdate POST)
|
|
184
|
+
// over plaintext http: the server may have processed the original.
|
|
185
|
+
!isIdempotentRequest(params)
|
|
186
|
+
) {
|
|
187
|
+
throw e;
|
|
188
|
+
}
|
|
189
|
+
log('trying fallback to http');
|
|
190
|
+
return enhancedFetch(url.replace(/^https:/, 'http:'), params, true);
|
|
191
|
+
});
|
|
192
192
|
};
|
package/.eslintrc.js
DELETED