mosquito-transport-js 0.2.2 → 0.2.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/package.json +4 -4
- package/src/helpers/EngineApi.js +0 -1
- package/src/helpers/utils.js +11 -5
- package/src/helpers/values.js +2 -2
- package/src/index.d.ts +19 -2
- package/src/index.js +20 -8
- package/src/products/auth/accessor.js +1 -21
- package/src/products/database/validator.js +9 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mosquito-transport-js",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Javascript web sdk for mosquito-transport (https://github.com/deflexable/mosquito-transport)",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
13
|
-
"url": "git+https://github.com/
|
|
13
|
+
"url": "git+https://github.com/brainbehindx/mosquito-transport-js.git"
|
|
14
14
|
},
|
|
15
15
|
"keywords": [
|
|
16
16
|
"mosquito-transport",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"author": "Anthony Onabanjo <deflexable@gmail.com> (https://github.com/deflexable)",
|
|
26
26
|
"license": "MIT",
|
|
27
27
|
"bugs": {
|
|
28
|
-
"url": "https://github.com/
|
|
28
|
+
"url": "https://github.com/brainbehindx/mosquito-transport-js/issues"
|
|
29
29
|
},
|
|
30
|
-
"homepage": "https://github.com/
|
|
30
|
+
"homepage": "https://github.com/brainbehindx/mosquito-transport-js#readme",
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@types/crypto-js": "^4.2.1",
|
|
33
33
|
"@types/lodash": "^4.14.194",
|
package/src/helpers/EngineApi.js
CHANGED
|
@@ -14,7 +14,6 @@ const apis = {
|
|
|
14
14
|
_twitterSignin: (baseApi, ugly) => `${baseApi}/${ugly ? encodeBinary(apis._twitterSignin(baseApi)) : '_twitterSignin'}`,
|
|
15
15
|
_githubSignin: (baseApi, ugly) => `${baseApi}/${ugly ? encodeBinary(apis._githubSignin(baseApi)) : '_githubSignin'}`,
|
|
16
16
|
_signOut: (baseApi, ugly) => `${baseApi}/${ugly ? encodeBinary(apis._signOut(baseApi)) : '_signOut'}`,
|
|
17
|
-
_invalidateToken: (baseApi, ugly) => `${baseApi}/${ugly ? encodeBinary(apis._invalidateToken(baseApi)) : '_invalidateToken'}`,
|
|
18
17
|
_refreshAuthToken: (baseApi, ugly) => `${baseApi}/${ugly ? encodeBinary(apis._refreshAuthToken(baseApi)) : '_refreshAuthToken'}`,
|
|
19
18
|
_downloadFile: (baseApi, ugly) => `${baseApi}/${ugly ? encodeBinary(apis._downloadFile(baseApi)) : '_downloadFile'}`,
|
|
20
19
|
_uploadFile: (baseApi, ugly) => `${baseApi}/${ugly ? encodeBinary(apis._uploadFile(baseApi)) : '_uploadFile'}`,
|
package/src/helpers/utils.js
CHANGED
|
@@ -7,7 +7,8 @@ export const updateCacheStore = () => {
|
|
|
7
7
|
try { window } catch (_) { return; }
|
|
8
8
|
const {
|
|
9
9
|
cachePassword = DEFAULT_CACHE_PASSWORD,
|
|
10
|
-
cacheProtocol = CACHE_PROTOCOL.LOCAL_STORAGE
|
|
10
|
+
cacheProtocol = CACHE_PROTOCOL.LOCAL_STORAGE,
|
|
11
|
+
io
|
|
11
12
|
} = Scoped.ReleaseCacheData;
|
|
12
13
|
|
|
13
14
|
clearTimeout(Scoped.cacheStorageReducer);
|
|
@@ -18,7 +19,9 @@ export const updateCacheStore = () => {
|
|
|
18
19
|
cachePassword
|
|
19
20
|
);
|
|
20
21
|
|
|
21
|
-
if (
|
|
22
|
+
if (io) {
|
|
23
|
+
io.ouput(txt);
|
|
24
|
+
} else if (cacheProtocol === CACHE_PROTOCOL.LOCAL_STORAGE) {
|
|
22
25
|
window.localStorage.setItem(CACHE_STORAGE_PATH, txt);
|
|
23
26
|
}
|
|
24
27
|
}, 500);
|
|
@@ -28,17 +31,20 @@ export const releaseCacheStore = async (builder) => {
|
|
|
28
31
|
try { window } catch (_) { return; }
|
|
29
32
|
const {
|
|
30
33
|
cachePassword = DEFAULT_CACHE_PASSWORD,
|
|
31
|
-
cacheProtocol = CACHE_PROTOCOL.LOCAL_STORAGE
|
|
34
|
+
cacheProtocol = CACHE_PROTOCOL.LOCAL_STORAGE,
|
|
35
|
+
io
|
|
32
36
|
} = builder;
|
|
33
37
|
|
|
34
38
|
let txt;
|
|
35
39
|
|
|
36
|
-
if (
|
|
40
|
+
if (io) {
|
|
41
|
+
txt = await io.input();
|
|
42
|
+
} else if (cacheProtocol === CACHE_PROTOCOL.LOCAL_STORAGE) {
|
|
37
43
|
txt = window.localStorage.getItem(CACHE_STORAGE_PATH);
|
|
38
44
|
}
|
|
39
45
|
|
|
40
46
|
const j = JSON.parse(decryptString(txt || '', cachePassword, cachePassword) || '{}');
|
|
41
|
-
|
|
47
|
+
|
|
42
48
|
Object.entries(j).forEach(([k, v]) => {
|
|
43
49
|
CacheStore[k] = v;
|
|
44
50
|
});
|
package/src/helpers/values.js
CHANGED
|
@@ -37,8 +37,8 @@ export const WRITE_OPS = {
|
|
|
37
37
|
$MAX: '$max',
|
|
38
38
|
$MIN: '$min',
|
|
39
39
|
$MUL: '$mul',
|
|
40
|
-
$RENAME: '$rename'
|
|
41
|
-
|
|
40
|
+
$RENAME: '$rename',
|
|
41
|
+
$SET_ON_INSERT: '$setOnInsert'
|
|
42
42
|
};
|
|
43
43
|
export const WRITE_OPS_LIST = Object.values(WRITE_OPS);
|
|
44
44
|
|
package/src/index.d.ts
CHANGED
|
@@ -25,9 +25,26 @@ interface mtimestamp { $timestamp: 'now' }
|
|
|
25
25
|
export const TIMESTAMP: mtimestamp;
|
|
26
26
|
export function DOCUMENT_EXTRACTION(path: string): { $dynamicValue: number };
|
|
27
27
|
|
|
28
|
+
interface ReleaseCacheOption_IO {
|
|
29
|
+
/**
|
|
30
|
+
* This password will be used to encrypt data stored locally
|
|
31
|
+
*/
|
|
32
|
+
cachePassword?: string;
|
|
33
|
+
io: {
|
|
34
|
+
/**
|
|
35
|
+
* feeds mosquito-transport data
|
|
36
|
+
*/
|
|
37
|
+
input: () => string;
|
|
38
|
+
/**
|
|
39
|
+
* emits mosquito-transport internal data
|
|
40
|
+
*/
|
|
41
|
+
output: (data: string) => void;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
28
45
|
interface ReleaseCacheOption {
|
|
29
46
|
/**
|
|
30
|
-
* This password will be used to
|
|
47
|
+
* This password will be used to encrypt data stored locally
|
|
31
48
|
*/
|
|
32
49
|
cachePassword?: string;
|
|
33
50
|
/**
|
|
@@ -61,7 +78,7 @@ interface BatchWriteConfig extends WriteConfig {
|
|
|
61
78
|
|
|
62
79
|
export class MosquitoTransport {
|
|
63
80
|
constructor(config: MTConfig);
|
|
64
|
-
static releaseCache(option?: ReleaseCacheOption): void;
|
|
81
|
+
static releaseCache(option?: ReleaseCacheOption | ReleaseCacheOption_IO): void;
|
|
65
82
|
getDatabase(dbName?: string, dbUrl?: string): GetDatabase;
|
|
66
83
|
collection(path: string): MTCollection;
|
|
67
84
|
auth(): MTAuth;
|
package/src/index.js
CHANGED
|
@@ -300,14 +300,26 @@ export class MosquitoTransport {
|
|
|
300
300
|
const validateReleaseCacheProp = (prop) => {
|
|
301
301
|
const cacheList = [...Object.values(CACHE_PROTOCOL)];
|
|
302
302
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
if (
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
303
|
+
if (prop?.io) {
|
|
304
|
+
Object.entries(prop).forEach(([k, v]) => {
|
|
305
|
+
if (k === 'input' || k === 'output') {
|
|
306
|
+
if (typeof v !== 'function')
|
|
307
|
+
throw `Invalid value supplied to ${k}, expected a function but got "${v}"`;
|
|
308
|
+
} else if (k === 'cachePassword') {
|
|
309
|
+
if (typeof v !== 'string' || v.trim().length <= 0)
|
|
310
|
+
throw `Invalid value supplied to cachePassword, value must be a string and greater than 0 characters`;
|
|
311
|
+
} else throw `Unexpected property named ${k}`;
|
|
312
|
+
});
|
|
313
|
+
} else {
|
|
314
|
+
Object.entries(prop).forEach(([k, v]) => {
|
|
315
|
+
if (k === 'cachePassword') {
|
|
316
|
+
if (typeof v !== 'string' || v.trim().length <= 0)
|
|
317
|
+
throw `Invalid value supplied to cachePassword, value must be a string and greater than 0 characters`;
|
|
318
|
+
} else if (k === 'cacheProtocol') {
|
|
319
|
+
if (!cacheList.includes(`${v}`)) throw `unknown value supplied to ${k}, expected any of ${cacheList}`;
|
|
320
|
+
} else throw `Unexpected property named ${k}`;
|
|
321
|
+
});
|
|
322
|
+
}
|
|
311
323
|
}
|
|
312
324
|
|
|
313
325
|
const validator = {
|
|
@@ -102,7 +102,6 @@ const refreshToken = (builder, processRef, remainRetries = 7, initialRetries = 7
|
|
|
102
102
|
if (isForceRefresh) Scoped.InitiatedForcedToken[projectUrl] = true;
|
|
103
103
|
updateCacheStore();
|
|
104
104
|
initTokenRefresher(builder);
|
|
105
|
-
invalidateToken(builder, token);
|
|
106
105
|
} else reject(lostProcess.simpleError);
|
|
107
106
|
} catch (e) {
|
|
108
107
|
if (e.simpleError) {
|
|
@@ -128,23 +127,4 @@ const refreshToken = (builder, processRef, remainRetries = 7, initialRetries = 7
|
|
|
128
127
|
}, projectUrl);
|
|
129
128
|
}
|
|
130
129
|
}
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
export const invalidateToken = async (builder, token) => {
|
|
134
|
-
try {
|
|
135
|
-
const { projectUrl, accessKey, uglify, serverE2E_PublicKey } = builder;
|
|
136
|
-
await awaitReachableServer(projectUrl);
|
|
137
|
-
|
|
138
|
-
const [reqBuilder] = buildFetchInterface({
|
|
139
|
-
body: { token },
|
|
140
|
-
accessKey,
|
|
141
|
-
uglify,
|
|
142
|
-
serverE2E_PublicKey
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
const r = await (await fetch(EngineApi._invalidateToken(projectUrl, uglify), reqBuilder)).json();
|
|
146
|
-
if (r.simpleError) throw r;
|
|
147
|
-
} catch (e) {
|
|
148
|
-
throw simplifyCaughtError(e).simpleError;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
130
|
+
});
|
|
@@ -202,12 +202,19 @@ const evaluateFilter = (data = {}, filter = {}) => {
|
|
|
202
202
|
} else logics.push(false);
|
|
203
203
|
} else if ($ === $TEXT) {
|
|
204
204
|
if (commandSplit.slice(-1)[0].$ === '$search') {
|
|
205
|
-
const { $caseSensitive, $
|
|
205
|
+
const { $caseSensitive, $search, $field } = filter.$text;
|
|
206
206
|
|
|
207
207
|
if (typeof value !== 'string' || typeof $search !== 'string')
|
|
208
208
|
throw `$search must have a string value`;
|
|
209
|
+
if (!$field) throw '"$field" is required inside "$text" operator when "disableCache=false"';
|
|
210
|
+
const fieldArr = Array.isArray($field) ? $field : [$field];
|
|
209
211
|
|
|
210
|
-
|
|
212
|
+
fieldArr.forEach(v => {
|
|
213
|
+
if (typeof v !== 'string' || !v.trim())
|
|
214
|
+
throw `invalid item inside "$field", expected a non-empty string but got "${v}"`;
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
const searchTxt = fieldArr.map(v => getLodash(dataObj, v || '')).map(v =>
|
|
211
218
|
`${typeof v === 'string' ? v :
|
|
212
219
|
Array.isArray(v) ? v.map(v => typeof v === 'string' ? v : '').join(' ').trim() : ''}`.trim()
|
|
213
220
|
).join(' ').trim();
|