react-native-mosquito-transport 0.0.52 → 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 +1 -1
- package/src/helpers/peripherals.js +0 -16
- package/src/helpers/utils.js +59 -17
- package/src/helpers/variables.js +1 -0
- package/src/index.js +16 -30
- package/src/products/auth/accessor.js +18 -8
- package/src/products/auth/index.js +6 -9
- package/src/products/database/index.js +43 -47
- package/src/products/http_callable/index.js +10 -14
package/package.json
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Buffer } from "buffer";
|
|
2
|
-
import { ServerReachableListener } from "./listeners";
|
|
3
2
|
import naclPkg from 'tweetnacl';
|
|
4
3
|
import { deserialize, serialize } from "entity-serializer";
|
|
5
4
|
import { sha256 } from 'react-native-sha256';
|
|
@@ -8,14 +7,6 @@ import { grab } from "poke-object";
|
|
|
8
7
|
|
|
9
8
|
const { box, randomBytes } = naclPkg;
|
|
10
9
|
|
|
11
|
-
export const listenReachableServer = (callback, projectUrl) => {
|
|
12
|
-
let lastValue;
|
|
13
|
-
return ServerReachableListener.listenToPersist(projectUrl, t => {
|
|
14
|
-
if (typeof t === 'boolean' && t !== lastValue) callback?.(t);
|
|
15
|
-
lastValue = t;
|
|
16
|
-
});
|
|
17
|
-
};
|
|
18
|
-
|
|
19
10
|
export const prefixStoragePath = (path, prefix = 'file:///') => {
|
|
20
11
|
let cleanedPath = path.replace(/^[^/]+:\/{1,3}/, '');
|
|
21
12
|
|
|
@@ -30,13 +21,6 @@ export const prefixStoragePath = (path, prefix = 'file:///') => {
|
|
|
30
21
|
return `${prefix}${cleanedPath}`;
|
|
31
22
|
};
|
|
32
23
|
|
|
33
|
-
export const niceTry = (promise) => new Promise(async resolve => {
|
|
34
|
-
try {
|
|
35
|
-
const r = await promise();
|
|
36
|
-
resolve(r);
|
|
37
|
-
} catch (e) { resolve(); }
|
|
38
|
-
});
|
|
39
|
-
|
|
40
24
|
export const normalizeRoute = (route = '') => route.split('').map((v, i, a) =>
|
|
41
25
|
((!i && v === '/') || (i === a.length - 1 && v === '/') || (i && a[i - 1] === '/' && v === '/')) ? '' : v
|
|
42
26
|
).join('');
|
package/src/helpers/utils.js
CHANGED
|
@@ -7,6 +7,8 @@ import { breakDbMap, purgeRedundantRecords } from "./purger";
|
|
|
7
7
|
import { FS_PATH, getSystem } from "./fs_manager";
|
|
8
8
|
import { Buffer } from "buffer";
|
|
9
9
|
import { basicClone } from "./basic_clone";
|
|
10
|
+
import engine_api from "./engine_api";
|
|
11
|
+
import { AppState } from "react-native";
|
|
10
12
|
|
|
11
13
|
const { FILE_NAME, TABLE_NAME } = FS_PATH;
|
|
12
14
|
|
|
@@ -153,31 +155,71 @@ export const awaitStore = () => new Promise(resolve => {
|
|
|
153
155
|
});
|
|
154
156
|
});
|
|
155
157
|
|
|
156
|
-
export const
|
|
157
|
-
if (Scoped.
|
|
158
|
-
|
|
159
|
-
|
|
158
|
+
export const checkAreYouOk = (projectUrl) => {
|
|
159
|
+
if (!Scoped.AreYouOkPromise[projectUrl]) {
|
|
160
|
+
const promise = fetch(engine_api._areYouOk(projectUrl), { credentials: 'omit' })
|
|
161
|
+
.then(async r => (await r.json()).status === 'yes')
|
|
162
|
+
.catch(() => false)
|
|
163
|
+
.then(async connected => {
|
|
164
|
+
Scoped.IS_CONNECTED[projectUrl] = connected;
|
|
165
|
+
ServerReachableListener.dispatchPersist(projectUrl, connected);
|
|
166
|
+
|
|
167
|
+
delete Scoped.AreYouOkPromise[projectUrl];
|
|
168
|
+
return connected;
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
Scoped.AreYouOkPromise[projectUrl] = promise;
|
|
160
172
|
}
|
|
161
|
-
|
|
162
|
-
|
|
173
|
+
|
|
174
|
+
return Scoped.AreYouOkPromise[projectUrl];
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export const listenReachableServer = (callback, projectUrl) => {
|
|
178
|
+
let lastValue;
|
|
179
|
+
return ServerReachableListener.listenToPersist(projectUrl, t => {
|
|
180
|
+
if (typeof t === 'boolean' && t !== lastValue) callback?.(t);
|
|
181
|
+
lastValue = t;
|
|
182
|
+
});
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
export const awaitReachableServer = (projectUrl) =>
|
|
186
|
+
new Promise(async resolve => {
|
|
187
|
+
if (AppState.currentState !== 'active') {
|
|
188
|
+
if (await checkAreYouOk(projectUrl)) {
|
|
189
|
+
resolve();
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (Scoped.IS_CONNECTED[projectUrl]) {
|
|
163
195
|
resolve();
|
|
164
|
-
|
|
196
|
+
return;
|
|
165
197
|
}
|
|
198
|
+
|
|
199
|
+
const l = listenReachableServer(t => {
|
|
200
|
+
if (!t) return;
|
|
201
|
+
resolve();
|
|
202
|
+
l();
|
|
203
|
+
}, projectUrl);
|
|
166
204
|
});
|
|
167
|
-
});
|
|
168
205
|
|
|
169
|
-
export const getReachableServer = (projectUrl) =>
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
206
|
+
export const getReachableServer = (projectUrl) =>
|
|
207
|
+
new Promise(async resolve => {
|
|
208
|
+
if (AppState.currentState !== 'active') {
|
|
209
|
+
resolve(await checkAreYouOk(projectUrl));
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (typeof Scoped.IS_CONNECTED[projectUrl] === 'boolean') {
|
|
214
|
+
resolve(Scoped.IS_CONNECTED[projectUrl]);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const l = listenReachableServer(t => {
|
|
176
219
|
resolve(t);
|
|
177
220
|
l();
|
|
178
|
-
}
|
|
221
|
+
}, projectUrl);
|
|
179
222
|
});
|
|
180
|
-
});
|
|
181
223
|
|
|
182
224
|
export const buildFetchInterface = async ({ body, authToken, method, uglify, serverE2E_PublicKey, extraHeaders }) => {
|
|
183
225
|
if (!uglify) body = JSON.stringify({ ...body });
|
package/src/helpers/variables.js
CHANGED
package/src/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import 'react-native-get-random-values';
|
|
2
|
-
import { deserializeE2E,
|
|
3
|
-
import { awaitReachableServer, awaitStore, releaseCacheStore } from "./helpers/utils";
|
|
2
|
+
import { deserializeE2E, serializeE2E } from "./helpers/peripherals";
|
|
3
|
+
import { awaitReachableServer, awaitStore, checkAreYouOk, listenReachableServer, releaseCacheStore } from "./helpers/utils";
|
|
4
4
|
import { CacheStore, Scoped } from "./helpers/variables";
|
|
5
5
|
import { MTCollection, batchWrite, onCollectionConnect, trySendPendingWrite } from "./products/database";
|
|
6
6
|
import { MTStorage } from "./products/storage";
|
|
@@ -23,8 +23,7 @@ const {
|
|
|
23
23
|
_listenDocument,
|
|
24
24
|
_startDisconnectWriteTask,
|
|
25
25
|
_cancelDisconnectWriteTask,
|
|
26
|
-
_listenUserVerification
|
|
27
|
-
_areYouOk
|
|
26
|
+
_listenUserVerification
|
|
28
27
|
} = EngineApi;
|
|
29
28
|
|
|
30
29
|
// https://socket.io/docs/v3/emit-cheatsheet/#reserved-events
|
|
@@ -63,7 +62,7 @@ class RNMT {
|
|
|
63
62
|
triggerAuthToken(projectUrl);
|
|
64
63
|
initTokenRefresher({ config: this.config, forceRefresh: true });
|
|
65
64
|
|
|
66
|
-
let isConnected, recentToken
|
|
65
|
+
let isConnected, recentToken;
|
|
67
66
|
|
|
68
67
|
const socket = io(`${this.config.wsPrefix}://${this.config.baseUrl}`, {
|
|
69
68
|
transports: ['websocket', 'polling', 'flashsocket'],
|
|
@@ -75,7 +74,6 @@ class RNMT {
|
|
|
75
74
|
});
|
|
76
75
|
|
|
77
76
|
let connectionIte = 0;
|
|
78
|
-
let chainedPromise;
|
|
79
77
|
const setConnected = c => {
|
|
80
78
|
isConnected = c;
|
|
81
79
|
Scoped.IS_CONNECTED[projectUrl] = isConnected;
|
|
@@ -91,28 +89,17 @@ class RNMT {
|
|
|
91
89
|
});
|
|
92
90
|
};
|
|
93
91
|
|
|
94
|
-
const onDisconnect = () => {
|
|
95
|
-
++connectionIte;
|
|
96
|
-
setConnected(isVirtualMachineFocused ? false : null);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
92
|
const manualCheckConnection = () => {
|
|
100
|
-
if (chainedPromise) return;
|
|
101
93
|
const ref = ++connectionIte;
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
} else throw null;
|
|
112
|
-
}).catch(() => {
|
|
113
|
-
clearTimeout(timer);
|
|
114
|
-
chainedPromise = undefined;
|
|
115
|
-
if (ref === connectionIte) onDisconnect();
|
|
94
|
+
|
|
95
|
+
checkAreYouOk(projectUrl).then(ok => {
|
|
96
|
+
if (ref !== connectionIte) return;
|
|
97
|
+
if (ok) {
|
|
98
|
+
onConnect();
|
|
99
|
+
} else {
|
|
100
|
+
++connectionIte;
|
|
101
|
+
isConnected = false;
|
|
102
|
+
}
|
|
116
103
|
});
|
|
117
104
|
}
|
|
118
105
|
|
|
@@ -128,7 +115,6 @@ class RNMT {
|
|
|
128
115
|
});
|
|
129
116
|
|
|
130
117
|
AppState.addEventListener('change', s => {
|
|
131
|
-
isVirtualMachineFocused = s === 'active';
|
|
132
118
|
manualCheckConnection();
|
|
133
119
|
});
|
|
134
120
|
|
|
@@ -352,7 +338,7 @@ class RNMT {
|
|
|
352
338
|
makeSocketCallback();
|
|
353
339
|
const reloadIntance = async () => {
|
|
354
340
|
if (!disableAuth) await awaitRefreshToken(projectUrl);
|
|
355
|
-
if (initIte === instance_id) remountInit();
|
|
341
|
+
if (initIte === instance_id && !hasCancelled) remountInit();
|
|
356
342
|
}
|
|
357
343
|
|
|
358
344
|
if (AppState.currentState === 'active') {
|
|
@@ -387,8 +373,7 @@ class RNMT {
|
|
|
387
373
|
if (initIte !== instance_id || wasHandled) return;
|
|
388
374
|
wasHandled = true;
|
|
389
375
|
clearSocket();
|
|
390
|
-
if (r === 'io client disconnect')
|
|
391
|
-
if (r === 'io server disconnect') {
|
|
376
|
+
if (r === 'io client disconnect' || r === 'io server disconnect') {
|
|
392
377
|
resultant.destroy();
|
|
393
378
|
} else reconnect(0);
|
|
394
379
|
});
|
|
@@ -478,6 +463,7 @@ class RNMT {
|
|
|
478
463
|
}
|
|
479
464
|
},
|
|
480
465
|
destroy: () => {
|
|
466
|
+
if (hasCancelled) return;
|
|
481
467
|
hasCancelled = true;
|
|
482
468
|
tokenListener?.();
|
|
483
469
|
clearForegroundListener();
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { doSignOut, revokeAuthIntance } from "./index.js";
|
|
2
2
|
import EngineApi from "../../helpers/engine_api";
|
|
3
3
|
import { AuthTokenListener, TokenRefreshListener } from "../../helpers/listeners";
|
|
4
|
-
import { decodeBinary, deserializeE2E
|
|
5
|
-
import { awaitStore, buildFetchInterface, buildFetchResult, updateCacheStore } from "../../helpers/utils";
|
|
4
|
+
import { decodeBinary, deserializeE2E } from "../../helpers/peripherals";
|
|
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 }) => {
|
|
@@ -208,12 +221,9 @@ const refreshToken = (builder, remainRetries = 1, isForceRefresh) =>
|
|
|
208
221
|
);
|
|
209
222
|
console.error(`refreshToken retry limit exceeded err:`, e);
|
|
210
223
|
} else {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
refreshToken(builder, remainRetries - 1, isForceRefresh).then(resolve, reject);
|
|
215
|
-
}
|
|
216
|
-
}, projectUrl);
|
|
224
|
+
awaitReachableServer(projectUrl).then(() => {
|
|
225
|
+
refreshToken(builder, remainRetries - 1, isForceRefresh).then(resolve, reject);
|
|
226
|
+
});
|
|
217
227
|
}
|
|
218
228
|
}
|
|
219
229
|
});
|
|
@@ -14,8 +14,7 @@ const {
|
|
|
14
14
|
_customSignin,
|
|
15
15
|
_customSignup,
|
|
16
16
|
_googleSignin,
|
|
17
|
-
_appleSignin
|
|
18
|
-
_areYouOk
|
|
17
|
+
_appleSignin
|
|
19
18
|
} = EngineApi;
|
|
20
19
|
|
|
21
20
|
export default class MTAuth {
|
|
@@ -55,11 +54,13 @@ export default class MTAuth {
|
|
|
55
54
|
const processID = ++lastInitRef;
|
|
56
55
|
await awaitRefreshToken(projectUrl);
|
|
57
56
|
|
|
57
|
+
if (processID !== lastInitRef || hasCancelled) return;
|
|
58
|
+
|
|
58
59
|
if (!Scoped.AuthJWTToken[projectUrl]) {
|
|
59
60
|
onError?.(simplifyError('user_login_required', 'You must be signed-in to use this method').simpleError);
|
|
60
61
|
return;
|
|
61
62
|
}
|
|
62
|
-
|
|
63
|
+
|
|
63
64
|
const mtoken = Scoped.AuthJWTToken[projectUrl],
|
|
64
65
|
[reqBuilder, [privateKey]] = uglify ? await serializeE2E({ mtoken }, undefined, serverE2E_PublicKey) : [null, []];
|
|
65
66
|
|
|
@@ -252,6 +253,7 @@ const clearCacheForSignout = (builder, disposeEmulated) => {
|
|
|
252
253
|
purgeCache(projectUrl, true);
|
|
253
254
|
if (disposeEmulated) getEmulatedLinks(projectUrl).forEach(e => purgeCache(e));
|
|
254
255
|
|
|
256
|
+
clearInterval(Scoped.TokenRefreshTimer[projectUrl]);
|
|
255
257
|
setTimeout(() => {
|
|
256
258
|
initTokenRefresher({ config: builder });
|
|
257
259
|
}, 600);
|
|
@@ -291,12 +293,7 @@ export const purgePendingToken = async (nodeId) => {
|
|
|
291
293
|
|
|
292
294
|
if (!token) return;
|
|
293
295
|
try {
|
|
294
|
-
|
|
295
|
-
try {
|
|
296
|
-
isConnected = (await (await fetch(_areYouOk(projectUrl), { credentials: 'omit' })).json()).status === 'yes';
|
|
297
|
-
} catch (_) { }
|
|
298
|
-
|
|
299
|
-
if (!isConnected) await awaitReachableServer(projectUrl);
|
|
296
|
+
await awaitReachableServer(projectUrl);
|
|
300
297
|
|
|
301
298
|
const [reqBuilder] = await buildFetchInterface({
|
|
302
299
|
body: { token, r_token },
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { io } from "socket.io-client";
|
|
2
2
|
import EngineApi from "../../helpers/engine_api";
|
|
3
3
|
import { DatabaseRecordsListener } from "../../helpers/listeners";
|
|
4
|
-
import { deserializeE2E,
|
|
4
|
+
import { deserializeE2E, serializeE2E } from "../../helpers/peripherals";
|
|
5
5
|
import { awaitReachableServer, awaitStore, buildFetchInterface, buildFetchResult, getReachableServer, updateCacheStore } from "../../helpers/utils";
|
|
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";
|
|
@@ -158,7 +158,6 @@ const listenDocument = (callback, onError, builder, config) => {
|
|
|
158
158
|
hasRespond,
|
|
159
159
|
cacheListener,
|
|
160
160
|
lastInitRef = 0,
|
|
161
|
-
connectedListener,
|
|
162
161
|
lastSnapshot;
|
|
163
162
|
|
|
164
163
|
const dispatchSnapshot = s => {
|
|
@@ -179,11 +178,10 @@ const listenDocument = (callback, onError, builder, config) => {
|
|
|
179
178
|
|
|
180
179
|
awaitStore().then(() => {
|
|
181
180
|
if (hasCancelled) return;
|
|
182
|
-
|
|
183
|
-
connectedListener();
|
|
181
|
+
getReachableServer(projectUrl).then(connected => {
|
|
184
182
|
if (!connected && !hasRespond && !hasCancelled && shouldCache)
|
|
185
183
|
DatabaseRecordsListener.dispatch('d', processId);
|
|
186
|
-
}
|
|
184
|
+
});
|
|
187
185
|
});
|
|
188
186
|
}
|
|
189
187
|
|
|
@@ -260,7 +258,7 @@ const listenDocument = (callback, onError, builder, config) => {
|
|
|
260
258
|
if (processID !== lastInitRef || hasCancelled) return;
|
|
261
259
|
|
|
262
260
|
const reloadIntance = async () => {
|
|
263
|
-
if (processID
|
|
261
|
+
if (processID === lastInitRef && !hasCancelled) remountInit();
|
|
264
262
|
}
|
|
265
263
|
|
|
266
264
|
if (AppState.currentState === 'active') {
|
|
@@ -289,8 +287,9 @@ const listenDocument = (callback, onError, builder, config) => {
|
|
|
289
287
|
if (processID !== lastInitRef || wasHandled) return;
|
|
290
288
|
wasHandled = true;
|
|
291
289
|
clearSocket();
|
|
292
|
-
if (r === 'io client disconnect' || r === 'io server disconnect')
|
|
293
|
-
|
|
290
|
+
if (r === 'io client disconnect' || r === 'io server disconnect') {
|
|
291
|
+
canceller();
|
|
292
|
+
} else reconnect(0);
|
|
294
293
|
});
|
|
295
294
|
};
|
|
296
295
|
|
|
@@ -321,15 +320,16 @@ const listenDocument = (callback, onError, builder, config) => {
|
|
|
321
320
|
}, projectUrl);
|
|
322
321
|
}
|
|
323
322
|
|
|
324
|
-
|
|
323
|
+
const canceller = () => {
|
|
325
324
|
if (hasCancelled) return;
|
|
326
325
|
hasCancelled = true;
|
|
327
|
-
connectedListener?.();
|
|
328
326
|
cacheListener?.();
|
|
329
327
|
tokenListener?.();
|
|
330
328
|
clearForegroundListener();
|
|
331
329
|
clearSocket();
|
|
332
330
|
}
|
|
331
|
+
|
|
332
|
+
return canceller;
|
|
333
333
|
};
|
|
334
334
|
|
|
335
335
|
const initOnDisconnectionTask = ({ builder, connectData, disconnectData }) => {
|
|
@@ -416,7 +416,7 @@ const initOnDisconnectionTask = ({ builder, connectData, disconnectData }) => {
|
|
|
416
416
|
|
|
417
417
|
const reloadIntance = async () => {
|
|
418
418
|
if (!disableAuth) await awaitRefreshToken(projectUrl);
|
|
419
|
-
if (processID
|
|
419
|
+
if (processID === lastInitRef && !hasCancelled) remountInit();
|
|
420
420
|
}
|
|
421
421
|
|
|
422
422
|
if (AppState.currentState === 'active') {
|
|
@@ -445,8 +445,9 @@ const initOnDisconnectionTask = ({ builder, connectData, disconnectData }) => {
|
|
|
445
445
|
if (processID !== lastInitRef || wasHandled) return;
|
|
446
446
|
wasHandled = true;
|
|
447
447
|
clearSocket();
|
|
448
|
-
if (r === 'io client disconnect' || r === 'io server disconnect')
|
|
449
|
-
|
|
448
|
+
if (r === 'io client disconnect' || r === 'io server disconnect') {
|
|
449
|
+
canceller();
|
|
450
|
+
} else reconnect(0);
|
|
450
451
|
});
|
|
451
452
|
};
|
|
452
453
|
|
|
@@ -477,18 +478,24 @@ const initOnDisconnectionTask = ({ builder, connectData, disconnectData }) => {
|
|
|
477
478
|
}, projectUrl);
|
|
478
479
|
}
|
|
479
480
|
|
|
480
|
-
|
|
481
|
+
const canceller = () => {
|
|
481
482
|
if (hasCancelled) return;
|
|
482
483
|
hasCancelled = true;
|
|
483
484
|
tokenListener?.();
|
|
484
485
|
clearForegroundListener();
|
|
485
486
|
if (socket) {
|
|
486
487
|
const thisSocket = socket;
|
|
487
|
-
|
|
488
|
-
thisSocket.
|
|
489
|
-
|
|
488
|
+
try {
|
|
489
|
+
thisSocket.timeout(5000).emitWithAck(_cancelDisconnectWriteTask(uglify)).finally(() => {
|
|
490
|
+
thisSocket.close();
|
|
491
|
+
});
|
|
492
|
+
} catch (error) {
|
|
493
|
+
console.warn('socket closure error:', error);
|
|
494
|
+
}
|
|
490
495
|
}
|
|
491
496
|
};
|
|
497
|
+
|
|
498
|
+
return canceller;
|
|
492
499
|
};
|
|
493
500
|
|
|
494
501
|
const countCollection = async (builder, config) => {
|
|
@@ -519,8 +526,7 @@ const countCollection = async (builder, config) => {
|
|
|
519
526
|
};
|
|
520
527
|
|
|
521
528
|
try {
|
|
522
|
-
if (!disableAuth
|
|
523
|
-
await awaitRefreshToken(projectUrl);
|
|
529
|
+
if (!disableAuth) await ensureActiveToken(projectUrl);
|
|
524
530
|
|
|
525
531
|
const [reqBuilder, [privateKey]] = await buildFetchInterface({
|
|
526
532
|
body: {
|
|
@@ -552,15 +558,12 @@ const countCollection = async (builder, config) => {
|
|
|
552
558
|
} else if (retries > maxRetries) {
|
|
553
559
|
finalize(undefined, { error: 'retry_limit_exceeded', message: `retry exceed limit(${maxRetries})` });
|
|
554
560
|
} else {
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
);
|
|
562
|
-
}
|
|
563
|
-
}, projectUrl);
|
|
561
|
+
awaitReachableServer(projectUrl).then(() => {
|
|
562
|
+
readValue().then(
|
|
563
|
+
e => { finalize(e); },
|
|
564
|
+
e => { finalize(undefined, e); }
|
|
565
|
+
);
|
|
566
|
+
});
|
|
564
567
|
}
|
|
565
568
|
}
|
|
566
569
|
});
|
|
@@ -672,8 +675,7 @@ const findObject = async (builder, initConfig) => {
|
|
|
672
675
|
}
|
|
673
676
|
}
|
|
674
677
|
|
|
675
|
-
if (!disableAuth
|
|
676
|
-
await awaitRefreshToken(projectUrl);
|
|
678
|
+
if (!disableAuth) await ensureActiveToken(projectUrl);
|
|
677
679
|
|
|
678
680
|
const [reqBuilder, [privateKey]] = await buildFetchInterface({
|
|
679
681
|
body: {
|
|
@@ -730,20 +732,18 @@ const findObject = async (builder, initConfig) => {
|
|
|
730
732
|
} else if (retries > maxRetries) {
|
|
731
733
|
finalize(undefined, { error: 'retry_limit_exceeded', message: `retry exceed limit(${maxRetries})` });
|
|
732
734
|
} else {
|
|
733
|
-
|
|
734
|
-
if (
|
|
735
|
+
awaitReachableServer(projectUrl).then(() => {
|
|
736
|
+
if (intruder) {
|
|
735
737
|
intruder.resolve = undefined;
|
|
736
738
|
intruder.reject = undefined;
|
|
737
|
-
onlineListener();
|
|
738
739
|
readValue().then(
|
|
739
740
|
e => { finalize(e); },
|
|
740
741
|
e => { finalize(undefined, e); }
|
|
741
742
|
);
|
|
742
743
|
}
|
|
743
|
-
}
|
|
744
|
+
});
|
|
744
745
|
|
|
745
746
|
const cleanseIntruder = () => {
|
|
746
|
-
onlineListener?.();
|
|
747
747
|
intruder = undefined;
|
|
748
748
|
}
|
|
749
749
|
|
|
@@ -837,8 +837,7 @@ const commitData = async (builder, value, type, config) => {
|
|
|
837
837
|
};
|
|
838
838
|
|
|
839
839
|
try {
|
|
840
|
-
if (!disableAuth
|
|
841
|
-
await awaitRefreshToken(projectUrl);
|
|
840
|
+
if (!disableAuth) await ensureActiveToken(projectUrl);
|
|
842
841
|
|
|
843
842
|
const [reqBuilder, [privateKey]] = await buildFetchInterface({
|
|
844
843
|
body: {
|
|
@@ -879,15 +878,12 @@ const commitData = async (builder, value, type, config) => {
|
|
|
879
878
|
);
|
|
880
879
|
} else {
|
|
881
880
|
if (delivery === DELIVERY.NO_CACHE_AWAIT) {
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
);
|
|
889
|
-
}
|
|
890
|
-
}, projectUrl);
|
|
881
|
+
awaitReachableServer(projectUrl).then(() => {
|
|
882
|
+
sendValue().then(
|
|
883
|
+
e => { finalize(e.a, undefined, e.c); },
|
|
884
|
+
e => { finalize(undefined, e.b, e.c); }
|
|
885
|
+
);
|
|
886
|
+
});
|
|
891
887
|
} else if (shouldCache) finalize({ status: 'queued' });
|
|
892
888
|
else finalize(undefined, simplifyCaughtError(e).simpleError);
|
|
893
889
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Buffer } from "buffer";
|
|
2
|
-
import { deserializeE2E,
|
|
3
|
-
import {
|
|
2
|
+
import { deserializeE2E, niceHash, normalizeRoute, serializeE2E } from "../../helpers/peripherals";
|
|
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'];
|
|
@@ -216,15 +215,12 @@ export const mfetch = async (input = '', init, config) => {
|
|
|
216
215
|
} else if (retries > maxRetries) {
|
|
217
216
|
finalize(undefined, simplifyCaughtError(e).simpleError);
|
|
218
217
|
} else {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
);
|
|
226
|
-
}
|
|
227
|
-
}, projectUrl);
|
|
218
|
+
awaitReachableServer(projectUrl).then(() => {
|
|
219
|
+
callFetch().then(
|
|
220
|
+
e => finalize(e),
|
|
221
|
+
e => finalize(undefined, e)
|
|
222
|
+
);
|
|
223
|
+
});
|
|
228
224
|
}
|
|
229
225
|
}
|
|
230
226
|
});
|