react-native-mosquito-transport 0.0.53 → 0.0.54
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,18 +157,13 @@ export const awaitStore = () => new Promise(resolve => {
|
|
|
157
157
|
|
|
158
158
|
export const checkAreYouOk = (projectUrl) => {
|
|
159
159
|
if (!Scoped.AreYouOkPromise[projectUrl]) {
|
|
160
|
-
const
|
|
161
|
-
const timer = setTimeout(() => {
|
|
162
|
-
signal.abort();
|
|
163
|
-
}, 9000);
|
|
164
|
-
const promise = fetch(engine_api._areYouOk(projectUrl), { credentials: 'omit', signal })
|
|
160
|
+
const promise = fetch(engine_api._areYouOk(projectUrl), { credentials: 'omit' })
|
|
165
161
|
.then(async r => (await r.json()).status === 'yes')
|
|
166
162
|
.catch(() => false)
|
|
167
163
|
.then(async connected => {
|
|
168
164
|
Scoped.IS_CONNECTED[projectUrl] = connected;
|
|
169
165
|
ServerReachableListener.dispatchPersist(projectUrl, connected);
|
|
170
166
|
|
|
171
|
-
clearTimeout(timer);
|
|
172
167
|
delete Scoped.AreYouOkPromise[projectUrl];
|
|
173
168
|
return connected;
|
|
174
169
|
});
|
package/src/index.js
CHANGED
|
@@ -74,7 +74,6 @@ class RNMT {
|
|
|
74
74
|
});
|
|
75
75
|
|
|
76
76
|
let connectionIte = 0;
|
|
77
|
-
let chainedPromise;
|
|
78
77
|
const setConnected = c => {
|
|
79
78
|
isConnected = c;
|
|
80
79
|
Scoped.IS_CONNECTED[projectUrl] = isConnected;
|
|
@@ -91,11 +90,9 @@ class RNMT {
|
|
|
91
90
|
};
|
|
92
91
|
|
|
93
92
|
const manualCheckConnection = () => {
|
|
94
|
-
if (chainedPromise) return;
|
|
95
93
|
const ref = ++connectionIte;
|
|
96
94
|
|
|
97
95
|
checkAreYouOk(projectUrl).then(ok => {
|
|
98
|
-
chainedPromise = undefined;
|
|
99
96
|
if (ref !== connectionIte) return;
|
|
100
97
|
if (ok) {
|
|
101
98
|
onConnect();
|
|
@@ -2,7 +2,7 @@ import { doSignOut, revokeAuthIntance } from "./index.js";
|
|
|
2
2
|
import EngineApi from "../../helpers/engine_api";
|
|
3
3
|
import { AuthTokenListener, TokenRefreshListener } from "../../helpers/listeners";
|
|
4
4
|
import { decodeBinary, deserializeE2E } from "../../helpers/peripherals";
|
|
5
|
-
import { awaitReachableServer, awaitStore, buildFetchInterface, buildFetchResult, updateCacheStore } from "../../helpers/utils";
|
|
5
|
+
import { awaitReachableServer, awaitStore, buildFetchInterface, buildFetchResult, getReachableServer, updateCacheStore } from "../../helpers/utils";
|
|
6
6
|
import { CacheStore, Scoped } from "../../helpers/variables";
|
|
7
7
|
import { simplifyError } from "simplify-error";
|
|
8
8
|
import { Validator } from "guard-object";
|
|
@@ -76,6 +76,19 @@ export const awaitRefreshToken = (projectUrl) =>
|
|
|
76
76
|
}
|
|
77
77
|
});
|
|
78
78
|
|
|
79
|
+
export const ensureActiveToken = async (projectUrl) => {
|
|
80
|
+
if (await getReachableServer(projectUrl)) {
|
|
81
|
+
await awaitRefreshToken(projectUrl);
|
|
82
|
+
} else {
|
|
83
|
+
const emulatedURL = CacheStore.EmulatedAuth[projectUrl];
|
|
84
|
+
const { token } = CacheStore.AuthStore[emulatedURL || projectUrl] || {};
|
|
85
|
+
|
|
86
|
+
if (token && await hasTokenExpire(emulatedURL || projectUrl)) {
|
|
87
|
+
throw 'unable to refreshed expired token because of unreachable internet connection';
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
79
92
|
export const listenTokenReady = (callback, projectUrl) => TokenRefreshListener.listenToPersist(projectUrl, callback);
|
|
80
93
|
|
|
81
94
|
export const initTokenRefresher = async ({ config, forceRefresh, justCheck }) => {
|
|
@@ -54,11 +54,13 @@ export default class MTAuth {
|
|
|
54
54
|
const processID = ++lastInitRef;
|
|
55
55
|
await awaitRefreshToken(projectUrl);
|
|
56
56
|
|
|
57
|
+
if (processID !== lastInitRef || hasCancelled) return;
|
|
58
|
+
|
|
57
59
|
if (!Scoped.AuthJWTToken[projectUrl]) {
|
|
58
60
|
onError?.(simplifyError('user_login_required', 'You must be signed-in to use this method').simpleError);
|
|
59
61
|
return;
|
|
60
62
|
}
|
|
61
|
-
|
|
63
|
+
|
|
62
64
|
const mtoken = Scoped.AuthJWTToken[projectUrl],
|
|
63
65
|
[reqBuilder, [privateKey]] = uglify ? await serializeE2E({ mtoken }, undefined, serverE2E_PublicKey) : [null, []];
|
|
64
66
|
|
|
@@ -251,6 +253,7 @@ const clearCacheForSignout = (builder, disposeEmulated) => {
|
|
|
251
253
|
purgeCache(projectUrl, true);
|
|
252
254
|
if (disposeEmulated) getEmulatedLinks(projectUrl).forEach(e => purgeCache(e));
|
|
253
255
|
|
|
256
|
+
clearInterval(Scoped.TokenRefreshTimer[projectUrl]);
|
|
254
257
|
setTimeout(() => {
|
|
255
258
|
initTokenRefresher({ config: builder });
|
|
256
259
|
}, 600);
|
|
@@ -6,7 +6,7 @@ import { awaitReachableServer, awaitStore, buildFetchInterface, buildFetchResult
|
|
|
6
6
|
import { CacheStore, Scoped } from "../../helpers/variables";
|
|
7
7
|
import { addPendingWrites, generateRecordID, getCountQuery, getRecord, insertCountQuery, insertRecord, listenQueryEntry, removePendingWrite, validateWriteValue } from "./accessor";
|
|
8
8
|
import { validateCollectionName, validateFilter, validateFindConfig, validateFindObject, validateListenFindConfig } from "./validator";
|
|
9
|
-
import { awaitRefreshToken, listenTokenReady } from "../auth/accessor";
|
|
9
|
+
import { awaitRefreshToken, ensureActiveToken, listenTokenReady } from "../auth/accessor";
|
|
10
10
|
import { DELIVERY, RETRIEVAL } from "../../helpers/values";
|
|
11
11
|
import { ObjectId } from "../../vendor/bson";
|
|
12
12
|
import { guardObject, Validator } from "guard-object";
|
|
@@ -526,8 +526,7 @@ const countCollection = async (builder, config) => {
|
|
|
526
526
|
};
|
|
527
527
|
|
|
528
528
|
try {
|
|
529
|
-
if (!disableAuth
|
|
530
|
-
await awaitRefreshToken(projectUrl);
|
|
529
|
+
if (!disableAuth) await ensureActiveToken(projectUrl);
|
|
531
530
|
|
|
532
531
|
const [reqBuilder, [privateKey]] = await buildFetchInterface({
|
|
533
532
|
body: {
|
|
@@ -676,8 +675,7 @@ const findObject = async (builder, initConfig) => {
|
|
|
676
675
|
}
|
|
677
676
|
}
|
|
678
677
|
|
|
679
|
-
if (!disableAuth
|
|
680
|
-
await awaitRefreshToken(projectUrl);
|
|
678
|
+
if (!disableAuth) await ensureActiveToken(projectUrl);
|
|
681
679
|
|
|
682
680
|
const [reqBuilder, [privateKey]] = await buildFetchInterface({
|
|
683
681
|
body: {
|
|
@@ -839,8 +837,7 @@ const commitData = async (builder, value, type, config) => {
|
|
|
839
837
|
};
|
|
840
838
|
|
|
841
839
|
try {
|
|
842
|
-
if (!disableAuth
|
|
843
|
-
await awaitRefreshToken(projectUrl);
|
|
840
|
+
if (!disableAuth) await ensureActiveToken(projectUrl);
|
|
844
841
|
|
|
845
842
|
const [reqBuilder, [privateKey]] = await buildFetchInterface({
|
|
846
843
|
body: {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Buffer } from "buffer";
|
|
2
2
|
import { deserializeE2E, niceHash, normalizeRoute, serializeE2E } from "../../helpers/peripherals";
|
|
3
|
-
import { awaitReachableServer, awaitStore
|
|
3
|
+
import { awaitReachableServer, awaitStore } from "../../helpers/utils";
|
|
4
4
|
import { RETRIEVAL } from "../../helpers/values";
|
|
5
5
|
import { Scoped } from "../../helpers/variables";
|
|
6
|
-
import {
|
|
6
|
+
import { ensureActiveToken, parseToken } from "../auth/accessor";
|
|
7
7
|
import { simplifyCaughtError } from "simplify-error";
|
|
8
8
|
import { guardObject, Validator } from "guard-object";
|
|
9
9
|
import { serialize } from "entity-serializer";
|
|
@@ -134,8 +134,7 @@ export const mfetch = async (input = '', init, config) => {
|
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
if (!disableAuth
|
|
138
|
-
await awaitRefreshToken(projectUrl);
|
|
137
|
+
if (!disableAuth) await ensureActiveToken(projectUrl);
|
|
139
138
|
|
|
140
139
|
const mtoken = disableAuth ? undefined : Scoped.AuthJWTToken[projectUrl];
|
|
141
140
|
const initType = rawHeader['content-type'];
|