react-native-mosquito-transport 0.0.54 → 0.0.55
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/package.json
CHANGED
package/src/helpers/utils.js
CHANGED
|
@@ -157,6 +157,9 @@ export const awaitStore = () => new Promise(resolve => {
|
|
|
157
157
|
|
|
158
158
|
export const checkAreYouOk = (projectUrl) => {
|
|
159
159
|
if (!Scoped.AreYouOkPromise[projectUrl]) {
|
|
160
|
+
Scoped.IS_CONNECTED[projectUrl] = undefined;
|
|
161
|
+
ServerReachableListener.dispatchPersist(projectUrl, undefined);
|
|
162
|
+
|
|
160
163
|
const promise = fetch(engine_api._areYouOk(projectUrl), { credentials: 'omit' })
|
|
161
164
|
.then(async r => (await r.json()).status === 'yes')
|
|
162
165
|
.catch(() => false)
|
|
@@ -182,25 +185,31 @@ export const listenReachableServer = (callback, projectUrl) => {
|
|
|
182
185
|
});
|
|
183
186
|
};
|
|
184
187
|
|
|
185
|
-
export const awaitReachableServer = (projectUrl) =>
|
|
186
|
-
new Promise(
|
|
187
|
-
|
|
188
|
-
if (
|
|
188
|
+
export const awaitReachableServer = (projectUrl, pauseForRetry) =>
|
|
189
|
+
new Promise(resolve => {
|
|
190
|
+
const check = async () => {
|
|
191
|
+
if (AppState.currentState !== 'active') {
|
|
192
|
+
if (await checkAreYouOk(projectUrl)) {
|
|
193
|
+
resolve();
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (Scoped.IS_CONNECTED[projectUrl]) {
|
|
189
199
|
resolve();
|
|
190
200
|
return;
|
|
191
201
|
}
|
|
192
|
-
}
|
|
193
202
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
203
|
+
const l = listenReachableServer(t => {
|
|
204
|
+
if (!t) return;
|
|
205
|
+
resolve();
|
|
206
|
+
l();
|
|
207
|
+
}, projectUrl);
|
|
197
208
|
}
|
|
198
209
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
l();
|
|
203
|
-
}, projectUrl);
|
|
210
|
+
if (pauseForRetry) {
|
|
211
|
+
setTimeout(check, Number.isInteger(pauseForRetry) ? pauseForRetry : 300);
|
|
212
|
+
} else check();
|
|
204
213
|
});
|
|
205
214
|
|
|
206
215
|
export const getReachableServer = (projectUrl) =>
|
package/src/index.d.ts
CHANGED
|
@@ -297,6 +297,14 @@ export interface FetchHttpConfig {
|
|
|
297
297
|
disableAuth?: boolean;
|
|
298
298
|
enableMinimizer?: boolean;
|
|
299
299
|
rawApproach?: boolean;
|
|
300
|
+
/**
|
|
301
|
+
* Wait for the server to come online if the response does not include a header with status 200.
|
|
302
|
+
*
|
|
303
|
+
* This ensures that the fetchHttp method only resolves when a response with status 200 is received; otherwise, it rejects if the server is online but continues returning a non-200 status
|
|
304
|
+
*
|
|
305
|
+
* @default false
|
|
306
|
+
*/
|
|
307
|
+
enforce200?: boolean;
|
|
300
308
|
}
|
|
301
309
|
|
|
302
310
|
type Delievery = 'default' | 'cache-no-await' | 'no-cache-no-await' | 'no-cache-await';
|
package/src/index.js
CHANGED
|
@@ -342,9 +342,7 @@ class RNMT {
|
|
|
342
342
|
}
|
|
343
343
|
|
|
344
344
|
if (AppState.currentState === 'active') {
|
|
345
|
-
|
|
346
|
-
awaitReachableServer(projectUrl).then(reloadIntance);
|
|
347
|
-
}, timeout);
|
|
345
|
+
awaitReachableServer(projectUrl, timeout).then(reloadIntance);
|
|
348
346
|
} else {
|
|
349
347
|
foregroundListener = AppState.addEventListener('change', s => {
|
|
350
348
|
if (s === 'active') {
|
|
@@ -375,7 +373,7 @@ class RNMT {
|
|
|
375
373
|
clearSocket();
|
|
376
374
|
if (r === 'io client disconnect' || r === 'io server disconnect') {
|
|
377
375
|
resultant.destroy();
|
|
378
|
-
} else reconnect(
|
|
376
|
+
} else reconnect(true);
|
|
379
377
|
});
|
|
380
378
|
|
|
381
379
|
clientPrivateKey = privateKey;
|
|
@@ -221,7 +221,7 @@ const refreshToken = (builder, remainRetries = 1, isForceRefresh) =>
|
|
|
221
221
|
);
|
|
222
222
|
console.error(`refreshToken retry limit exceeded err:`, e);
|
|
223
223
|
} else {
|
|
224
|
-
awaitReachableServer(projectUrl).then(() => {
|
|
224
|
+
awaitReachableServer(projectUrl, true).then(() => {
|
|
225
225
|
refreshToken(builder, remainRetries - 1, isForceRefresh).then(resolve, reject);
|
|
226
226
|
});
|
|
227
227
|
}
|
|
@@ -262,9 +262,7 @@ const listenDocument = (callback, onError, builder, config) => {
|
|
|
262
262
|
}
|
|
263
263
|
|
|
264
264
|
if (AppState.currentState === 'active') {
|
|
265
|
-
|
|
266
|
-
awaitReachableServer(projectUrl).then(reloadIntance);
|
|
267
|
-
}, timeout);
|
|
265
|
+
awaitReachableServer(projectUrl, timeout).then(reloadIntance);
|
|
268
266
|
} else {
|
|
269
267
|
foregroundListener = AppState.addEventListener('change', s => {
|
|
270
268
|
if (s === 'active') {
|
|
@@ -289,7 +287,7 @@ const listenDocument = (callback, onError, builder, config) => {
|
|
|
289
287
|
clearSocket();
|
|
290
288
|
if (r === 'io client disconnect' || r === 'io server disconnect') {
|
|
291
289
|
canceller();
|
|
292
|
-
} else reconnect(
|
|
290
|
+
} else reconnect(true);
|
|
293
291
|
});
|
|
294
292
|
};
|
|
295
293
|
|
|
@@ -420,9 +418,7 @@ const initOnDisconnectionTask = ({ builder, connectData, disconnectData }) => {
|
|
|
420
418
|
}
|
|
421
419
|
|
|
422
420
|
if (AppState.currentState === 'active') {
|
|
423
|
-
|
|
424
|
-
awaitReachableServer(projectUrl).then(reloadIntance);
|
|
425
|
-
}, timeout);
|
|
421
|
+
awaitReachableServer(projectUrl, timeout).then(reloadIntance);
|
|
426
422
|
} else {
|
|
427
423
|
foregroundListener = AppState.addEventListener('change', s => {
|
|
428
424
|
if (s === 'active') {
|
|
@@ -447,7 +443,7 @@ const initOnDisconnectionTask = ({ builder, connectData, disconnectData }) => {
|
|
|
447
443
|
clearSocket();
|
|
448
444
|
if (r === 'io client disconnect' || r === 'io server disconnect') {
|
|
449
445
|
canceller();
|
|
450
|
-
} else reconnect(
|
|
446
|
+
} else reconnect(true);
|
|
451
447
|
});
|
|
452
448
|
};
|
|
453
449
|
|
|
@@ -558,7 +554,7 @@ const countCollection = async (builder, config) => {
|
|
|
558
554
|
} else if (retries > maxRetries) {
|
|
559
555
|
finalize(undefined, { error: 'retry_limit_exceeded', message: `retry exceed limit(${maxRetries})` });
|
|
560
556
|
} else {
|
|
561
|
-
awaitReachableServer(projectUrl).then(() => {
|
|
557
|
+
awaitReachableServer(projectUrl, true).then(() => {
|
|
562
558
|
readValue().then(
|
|
563
559
|
e => { finalize(e); },
|
|
564
560
|
e => { finalize(undefined, e); }
|
|
@@ -732,7 +728,7 @@ const findObject = async (builder, initConfig) => {
|
|
|
732
728
|
} else if (retries > maxRetries) {
|
|
733
729
|
finalize(undefined, { error: 'retry_limit_exceeded', message: `retry exceed limit(${maxRetries})` });
|
|
734
730
|
} else {
|
|
735
|
-
awaitReachableServer(projectUrl).then(() => {
|
|
731
|
+
awaitReachableServer(projectUrl, true).then(() => {
|
|
736
732
|
if (intruder) {
|
|
737
733
|
intruder.resolve = undefined;
|
|
738
734
|
intruder.reject = undefined;
|
|
@@ -878,7 +874,7 @@ const commitData = async (builder, value, type, config) => {
|
|
|
878
874
|
);
|
|
879
875
|
} else {
|
|
880
876
|
if (delivery === DELIVERY.NO_CACHE_AWAIT) {
|
|
881
|
-
awaitReachableServer(projectUrl).then(() => {
|
|
877
|
+
awaitReachableServer(projectUrl, true).then(() => {
|
|
882
878
|
sendValue().then(
|
|
883
879
|
e => { finalize(e.a, undefined, e.c); },
|
|
884
880
|
e => { finalize(undefined, e.b, e.c); }
|
|
@@ -42,10 +42,11 @@ export const mfetch = async (input = '', init, config) => {
|
|
|
42
42
|
enableMinimizer: t => t === undefined || Validator.BOOLEAN(t),
|
|
43
43
|
rawApproach: t => t === undefined || Validator.BOOLEAN(t),
|
|
44
44
|
disableAuth: t => t === undefined || Validator.BOOLEAN(t),
|
|
45
|
-
retrieval: t => t === undefined || Object.values(RETRIEVAL).includes(t)
|
|
45
|
+
retrieval: t => t === undefined || Object.values(RETRIEVAL).includes(t),
|
|
46
|
+
enforce200: t => t === undefined || Validator.BOOLEAN(t)
|
|
46
47
|
}).validate(method);
|
|
47
48
|
|
|
48
|
-
const { retrieval = RETRIEVAL.DEFAULT, enableMinimizer, rawApproach } = method || {};
|
|
49
|
+
const { retrieval = RETRIEVAL.DEFAULT, enableMinimizer, rawApproach, enforce200 } = method || {};
|
|
49
50
|
const isLink = Validator.LINK(input);
|
|
50
51
|
const isBaseUrl = isLink || rawApproach;
|
|
51
52
|
const disableAuth = method?.disableAuth === undefined ? isBaseUrl : method?.disableAuth;
|
|
@@ -163,6 +164,8 @@ export const mfetch = async (input = '', init, config) => {
|
|
|
163
164
|
const { ok, type, status, statusText, redirected, url, headers, size } = f;
|
|
164
165
|
const simple = headers.get('simple_error');
|
|
165
166
|
|
|
167
|
+
if (enforce200 && status !== 200)
|
|
168
|
+
throw `expected response status to be 200 but got ${status}`;
|
|
166
169
|
if (!isLink && simple) throw { simpleError: JSON.parse(simple) };
|
|
167
170
|
|
|
168
171
|
const buffer = uglified ?
|
|
@@ -215,7 +218,7 @@ export const mfetch = async (input = '', init, config) => {
|
|
|
215
218
|
} else if (retries > maxRetries) {
|
|
216
219
|
finalize(undefined, simplifyCaughtError(e).simpleError);
|
|
217
220
|
} else {
|
|
218
|
-
awaitReachableServer(projectUrl).then(() => {
|
|
221
|
+
awaitReachableServer(projectUrl, true).then(() => {
|
|
219
222
|
callFetch().then(
|
|
220
223
|
e => finalize(e),
|
|
221
224
|
e => finalize(undefined, e)
|