mosquito-transport-js 0.2.4 → 0.2.6
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/TODO +2 -1
- package/package.json +7 -2
- package/src/helpers/peripherals.js +6 -3
- package/src/helpers/utils.js +1 -1
- package/src/helpers/values.js +10 -1
- package/src/index.d.ts +39 -2
- package/src/index.js +38 -16
- package/src/products/auth/index.js +3 -0
- package/src/products/database/accessor.js +4 -4
- package/src/products/database/index.js +1 -1
- package/src/products/database/validator.js +2 -2
package/TODO
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mosquito-transport-js",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
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",
|
|
@@ -33,8 +33,13 @@
|
|
|
33
33
|
"@types/lodash": "^4.14.194",
|
|
34
34
|
"buffer": "^6.0.3",
|
|
35
35
|
"crypto-js": "^4.2.0",
|
|
36
|
+
"fast-json-stable-stringify": "^2.1.0",
|
|
37
|
+
"guard-object": "^1.0.6",
|
|
36
38
|
"json-buffer": "^3.0.1",
|
|
37
|
-
"lodash": "^4.
|
|
39
|
+
"lodash.get": "^4.4.2",
|
|
40
|
+
"lodash.isequal": "^4.5.0",
|
|
41
|
+
"lodash.set": "^4.3.2",
|
|
42
|
+
"lodash.unset": "^4.5.2",
|
|
38
43
|
"set-large-timeout": "^1.0.1",
|
|
39
44
|
"socket.io-client": "^4.6.2",
|
|
40
45
|
"subscription-listener": "^1.1.2",
|
|
@@ -98,9 +98,12 @@ export const cloneInstance = (v) => {
|
|
|
98
98
|
return v;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
export const listenReachableServer = (callback, projectUrl) =>
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
export const listenReachableServer = (callback, projectUrl) => {
|
|
102
|
+
let lastValue;
|
|
103
|
+
return ServerReachableListener.listenTo(projectUrl, t => {
|
|
104
|
+
if (typeof t === 'boolean' && t !== lastValue) callback?.(t);
|
|
105
|
+
}, true);
|
|
106
|
+
}
|
|
104
107
|
|
|
105
108
|
export const prefixStoragePath = (path, prefix = 'file:///') => {
|
|
106
109
|
if (!path) return path;
|
package/src/helpers/utils.js
CHANGED
package/src/helpers/values.js
CHANGED
|
@@ -63,4 +63,13 @@ export const READ_OPS_LIST = Object.values(READ_OPS);
|
|
|
63
63
|
|
|
64
64
|
export const Regexs = {
|
|
65
65
|
LINK: () => /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig
|
|
66
|
-
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const AUTH_PROVIDER_ID = {
|
|
69
|
+
GOOGLE: 'google.com',
|
|
70
|
+
FACEBOOK: 'facebook.com',
|
|
71
|
+
PASSWORD: 'password',
|
|
72
|
+
TWITTER: 'x.com',
|
|
73
|
+
GITHUB: 'github.com',
|
|
74
|
+
APPLE: 'apple.com'
|
|
75
|
+
};
|
package/src/index.d.ts
CHANGED
|
@@ -25,6 +25,43 @@ interface mtimestamp { $timestamp: 'now' }
|
|
|
25
25
|
export const TIMESTAMP: mtimestamp;
|
|
26
26
|
export function DOCUMENT_EXTRACTION(path: string): { $dynamicValue: number };
|
|
27
27
|
|
|
28
|
+
type longitude = number;
|
|
29
|
+
type latitude = number;
|
|
30
|
+
|
|
31
|
+
export function GEO_JSON(latitude: latitude, longitude: longitude): {
|
|
32
|
+
type: "Point",
|
|
33
|
+
coordinates: [longitude, latitude],
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export function FIND_GEO_JSON(coordinates: [latitude, longitude], offSetMeters: number, centerMeters?: number): {
|
|
37
|
+
$near: {
|
|
38
|
+
$geometry: {
|
|
39
|
+
type: "Point",
|
|
40
|
+
coordinates: [longitude, latitude]
|
|
41
|
+
},
|
|
42
|
+
$minDistance: number | 0,
|
|
43
|
+
$maxDistance: number
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const AUTH_PROVIDER_ID: auth_provider_id;
|
|
48
|
+
|
|
49
|
+
interface auth_provider_id {
|
|
50
|
+
GOOGLE: 'google.com';
|
|
51
|
+
FACEBOOK: 'facebook.com';
|
|
52
|
+
PASSWORD: 'password';
|
|
53
|
+
TWITTER: 'x.com';
|
|
54
|
+
GITHUB: 'github.com';
|
|
55
|
+
APPLE: 'apple.com';
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
type auth_provider_id_values = auth_provider_id['GOOGLE'] |
|
|
59
|
+
auth_provider_id['FACEBOOK'] |
|
|
60
|
+
auth_provider_id['PASSWORD'] |
|
|
61
|
+
auth_provider_id['GITHUB'] |
|
|
62
|
+
auth_provider_id['TWITTER'] |
|
|
63
|
+
auth_provider_id['APPLE'];
|
|
64
|
+
|
|
28
65
|
interface ReleaseCacheOption_IO {
|
|
29
66
|
/**
|
|
30
67
|
* This password will be used to encrypt data stored locally
|
|
@@ -342,8 +379,8 @@ interface SignupResult extends SigninResult {
|
|
|
342
379
|
interface AuthData {
|
|
343
380
|
email?: string;
|
|
344
381
|
metadata: Object;
|
|
345
|
-
signupMethod:
|
|
346
|
-
currentAuthMethod:
|
|
382
|
+
signupMethod: auth_provider_id_values;
|
|
383
|
+
currentAuthMethod: auth_provider_id_values;
|
|
347
384
|
joinedOn: number;
|
|
348
385
|
uid: string;
|
|
349
386
|
claims: Object;
|
package/src/index.js
CHANGED
|
@@ -5,12 +5,12 @@ import { MTAuth } from "./products/auth";
|
|
|
5
5
|
import { MTCollection, batchWrite } from "./products/database";
|
|
6
6
|
import { MTStorage } from "./products/storage";
|
|
7
7
|
import { ServerReachableListener, TokenRefreshListener } from "./helpers/listeners";
|
|
8
|
-
import { initTokenRefresher, listenTokenReady, triggerAuthToken } from "./products/auth/accessor";
|
|
8
|
+
import { initTokenRefresher, listenToken, listenTokenReady, parseToken, triggerAuthToken } from "./products/auth/accessor";
|
|
9
9
|
import { TIMESTAMP, DOCUMENT_EXTRACTION, FIND_GEO_JSON, GEO_JSON } from "./products/database/types";
|
|
10
10
|
import { mfetch } from "./products/http_callable";
|
|
11
11
|
import { io } from "socket.io-client";
|
|
12
12
|
import { validateCollectionPath } from "./products/database/validator";
|
|
13
|
-
import { CACHE_PROTOCOL, Regexs } from "./helpers/values";
|
|
13
|
+
import { AUTH_PROVIDER_ID, CACHE_PROTOCOL, Regexs } from "./helpers/values";
|
|
14
14
|
import { trySendPendingWrite } from "./products/database/accessor";
|
|
15
15
|
import EngineApi from './helpers/EngineApi';
|
|
16
16
|
import { parse, stringify } from 'json-buffer';
|
|
@@ -47,21 +47,42 @@ export class MosquitoTransport {
|
|
|
47
47
|
triggerAuthToken(projectUrl);
|
|
48
48
|
initTokenRefresher({ ...this.config }, true);
|
|
49
49
|
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
auth: { _m_internal: true, _from_base: true }
|
|
53
|
-
});
|
|
50
|
+
const disconnectionGlich = {};
|
|
51
|
+
let socket, lastUid, lastSocketProcess = 0, hasInited;
|
|
54
52
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
});
|
|
53
|
+
listenToken((token, thisInited) => {
|
|
54
|
+
const user = token && parseToken(token);
|
|
58
55
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
56
|
+
const thisUid = (user?.uid || null);
|
|
57
|
+
if (lastUid === thisUid && (hasInited || !thisInited)) return;
|
|
58
|
+
if (!hasInited) hasInited = thisInited;
|
|
59
|
+
lastUid = thisUid;
|
|
60
|
+
|
|
61
|
+
if (lastSocketProcess) disconnectionGlich[lastSocketProcess] = true;
|
|
62
|
+
if (socket) socket.close();
|
|
63
|
+
|
|
64
|
+
const thisProcess = ++lastSocketProcess;
|
|
65
|
+
socket = io(`${this.config.wsPrefix}://${projectUrl.split('://')[1]}`, {
|
|
66
|
+
transports: ['websocket', 'polling', 'flashsocket'],
|
|
67
|
+
auth: {
|
|
68
|
+
_m_internal: true,
|
|
69
|
+
_from_base: true,
|
|
70
|
+
atoken: token
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
socket.on('_signal_signout', () => {
|
|
75
|
+
this.auth().signOut();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
socket.on('connect', () => {
|
|
79
|
+
ServerReachableListener.dispatch(projectUrl, true);
|
|
80
|
+
});
|
|
81
|
+
socket.on('disconnect', () => {
|
|
82
|
+
if (!disconnectionGlich[thisProcess])
|
|
83
|
+
ServerReachableListener.dispatch(projectUrl, false);
|
|
84
|
+
});
|
|
85
|
+
}, projectUrl);
|
|
65
86
|
|
|
66
87
|
listenReachableServer(c => {
|
|
67
88
|
Scoped.IS_CONNECTED[projectUrl] = c;
|
|
@@ -379,5 +400,6 @@ export {
|
|
|
379
400
|
TIMESTAMP,
|
|
380
401
|
DOCUMENT_EXTRACTION,
|
|
381
402
|
FIND_GEO_JSON,
|
|
382
|
-
GEO_JSON
|
|
403
|
+
GEO_JSON,
|
|
404
|
+
AUTH_PROVIDER_ID
|
|
383
405
|
};
|
|
@@ -2,10 +2,10 @@ import { IS_RAW_OBJECT, objToUniqueString, queryEntries, shuffleArray, sortArray
|
|
|
2
2
|
import { awaitStore, updateCacheStore } from "../../helpers/utils";
|
|
3
3
|
import { CacheStore } from "../../helpers/variables";
|
|
4
4
|
import { confirmFilterDoc } from "./validator";
|
|
5
|
-
import getLodash from 'lodash
|
|
6
|
-
import setLodash from 'lodash
|
|
7
|
-
import unsetLodash from 'lodash
|
|
8
|
-
import isEqual from 'lodash
|
|
5
|
+
import getLodash from 'lodash.get';
|
|
6
|
+
import setLodash from 'lodash.set';
|
|
7
|
+
import unsetLodash from 'lodash.unset';
|
|
8
|
+
import isEqual from 'lodash.isequal';
|
|
9
9
|
import { DEFAULT_DB_NAME, DEFAULT_DB_URL, DELIVERY, RETRIEVAL, WRITE_OPS, WRITE_OPS_LIST } from "../../helpers/values";
|
|
10
10
|
import { DatabaseRecordsListener } from "../../helpers/listeners";
|
|
11
11
|
|
|
@@ -8,7 +8,7 @@ import { addPendingWrites, generateRecordID, getRecord, insertRecord, listenQuer
|
|
|
8
8
|
import { validateCollectionPath, validateFilter, validateReadConfig, validateWriteValue } from "./validator";
|
|
9
9
|
import { awaitRefreshToken, listenToken } from "../auth/accessor";
|
|
10
10
|
import { DEFAULT_DB_NAME, DEFAULT_DB_URL, DELIVERY, RETRIEVAL } from "../../helpers/values";
|
|
11
|
-
import setLodash from 'lodash
|
|
11
|
+
import setLodash from 'lodash.set';
|
|
12
12
|
|
|
13
13
|
export class MTCollection {
|
|
14
14
|
constructor(config) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IS_DECIMAL_NUMBER, IS_RAW_OBJECT, IS_WHOLE_NUMBER, queryEntries } from "../../helpers/peripherals";
|
|
2
2
|
import { READ_OPS, READ_OPS_LIST, RETRIEVAL } from "../../helpers/values";
|
|
3
|
-
import getLodash from 'lodash
|
|
4
|
-
import isEqual from 'lodash
|
|
3
|
+
import getLodash from 'lodash.get';
|
|
4
|
+
import isEqual from 'lodash.isequal';
|
|
5
5
|
|
|
6
6
|
const dirn = ['desc', 'asc', 'ascending', 'descending'];
|
|
7
7
|
|