react-native-mosquito-transport 0.0.15 → 0.0.17

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 CHANGED
@@ -1,3 +1,4 @@
1
1
  - fix local cache query on sqlite and fs
2
2
  - fix and add all mongodb query and update operator
3
- - reauthenticate
3
+ - reauthenticate
4
+ - change `Object` in d.ts to [key: string]: any
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-mosquito-transport",
3
- "version": "0.0.15",
3
+ "version": "0.0.17",
4
4
  "description": "React native javascript sdk for mosquito-transport (https://github.com/deflexable/mosquito-transport)",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -31,8 +31,13 @@
31
31
  "@types/lodash": "^4.14.194",
32
32
  "buffer": "^6.0.3",
33
33
  "crypto-js": "^4.2.0",
34
+ "fast-json-stable-stringify": "^2.1.0",
35
+ "guard-object": "^1.0.6",
34
36
  "json-buffer": "^3.0.1",
35
- "lodash": "^4.17.21",
37
+ "lodash.get": "^4.4.2",
38
+ "lodash.isequal": "^4.5.0",
39
+ "lodash.set": "^4.3.2",
40
+ "lodash.unset": "^4.5.2",
36
41
  "react-native-get-random-values": "^1.9.0",
37
42
  "set-large-timeout": "^1.0.1",
38
43
  "socket.io-client": "^4.6.2",
@@ -98,9 +98,12 @@ export const cloneInstance = (v) => {
98
98
  return v;
99
99
  }
100
100
 
101
- export const listenReachableServer = (callback, projectUrl) => ServerReachableListener.listenTo(projectUrl, t => {
102
- if (typeof t === 'boolean') callback?.(t);
103
- }, true);
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;
@@ -70,4 +70,13 @@ export const READ_OPS_LIST = Object.values(READ_OPS);
70
70
 
71
71
  export const Regexs = {
72
72
  LINK: () => /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig
73
- }
73
+ };
74
+
75
+ export const AUTH_PROVIDER_ID = {
76
+ GOOGLE: 'google.com',
77
+ FACEBOOK: 'facebook.com',
78
+ PASSWORD: 'password',
79
+ TWITTER: 'x.com',
80
+ GITHUB: 'github.com',
81
+ APPLE: 'apple.com'
82
+ };
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
@@ -343,8 +380,8 @@ interface SignupResult extends SigninResult {
343
380
  interface AuthData {
344
381
  email?: string;
345
382
  metadata: Object;
346
- signupMethod: 'google' | 'apple' | 'custom' | 'github' | 'twitter' | 'facebook' | string;
347
- currentAuthMethod: 'google' | 'apple' | 'custom' | 'github' | 'twitter' | 'facebook' | string;
383
+ signupMethod: auth_provider_id_values;
384
+ currentAuthMethod: auth_provider_id_values;
348
385
  joinedOn: number;
349
386
  uid: string;
350
387
  claims: Object;
package/src/index.js CHANGED
@@ -6,12 +6,12 @@ import { MTAuth } from "./products/auth";
6
6
  import { MTCollection, batchWrite } from "./products/database";
7
7
  import { MTStorage } from "./products/storage";
8
8
  import { ServerReachableListener, TokenRefreshListener } from "./helpers/listeners";
9
- import { initTokenRefresher, listenTokenReady, triggerAuthToken } from "./products/auth/accessor";
9
+ import { initTokenRefresher, listenToken, listenTokenReady, parseToken, triggerAuthToken } from "./products/auth/accessor";
10
10
  import { TIMESTAMP, DOCUMENT_EXTRACTION, FIND_GEO_JSON, GEO_JSON } from "./products/database/types";
11
11
  import { mfetch } from "./products/http_callable";
12
12
  import { io } from "socket.io-client";
13
13
  import { validateCollectionPath } from "./products/database/validator";
14
- import { CACHE_PROTOCOL, Regexs } from "./helpers/values";
14
+ import { AUTH_PROVIDER_ID, CACHE_PROTOCOL, Regexs } from "./helpers/values";
15
15
  import { trySendPendingWrite } from "./products/database/accessor";
16
16
  import EngineApi from './helpers/EngineApi';
17
17
  import { parse, stringify } from 'json-buffer';
@@ -48,20 +48,41 @@ class RNMT {
48
48
  triggerAuthToken(projectUrl);
49
49
  initTokenRefresher({ ...this.config }, true);
50
50
 
51
- const socket = io(`${this.config.wsPrefix}://${projectUrl.split('://')[1]}`, {
52
- auth: { _m_internal: true, _from_base: true }
53
- });
51
+ const disconnectionGlich = {};
52
+ let socket, lastUid, lastSocketProcess = 0, hasInited;
54
53
 
55
- socket.on('_signal_signout', () => {
56
- this.auth().signOut();
57
- });
54
+ listenToken((token, thisInited) => {
55
+ const user = token && parseToken(token);
58
56
 
59
- socket.on('connect', () => {
60
- ServerReachableListener.dispatch(projectUrl, true);
61
- });
62
- socket.on('disconnect', () => {
63
- ServerReachableListener.dispatch(projectUrl, false);
64
- });
57
+ const thisUid = (user?.uid || null);
58
+ if (lastUid === thisUid && (hasInited || !thisInited)) return;
59
+ if (!hasInited) hasInited = thisInited;
60
+ lastUid = thisUid;
61
+
62
+ if (lastSocketProcess) disconnectionGlich[lastSocketProcess] = true;
63
+ if (socket) socket.close();
64
+
65
+ const thisProcess = ++lastSocketProcess;
66
+ socket = io(`${this.config.wsPrefix}://${projectUrl.split('://')[1]}`, {
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;
@@ -378,7 +399,8 @@ export {
378
399
  TIMESTAMP,
379
400
  DOCUMENT_EXTRACTION,
380
401
  FIND_GEO_JSON,
381
- GEO_JSON
402
+ GEO_JSON,
403
+ AUTH_PROVIDER_ID
382
404
  };
383
405
 
384
406
  export default RNMT;
@@ -118,6 +118,9 @@ export class MTAuth {
118
118
  }, this.builder.projectUrl);
119
119
  });
120
120
 
121
+ /**
122
+ * @type {import('../../index').RNMTAuth['listenAuth']}
123
+ */
121
124
  listenAuth = (callback) => {
122
125
  let lastTrig;
123
126
 
@@ -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/get';
6
- import setLodash from 'lodash/set';
7
- import unsetLodash from 'lodash/unset';
8
- import isEqual from 'lodash/isEqual';
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/set';
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/get';
4
- import isEqual from 'lodash/isEqual';
3
+ import getLodash from 'lodash.get';
4
+ import isEqual from 'lodash.isequal';
5
5
 
6
6
  const dirn = ['desc', 'asc', 'ascending', 'descending'];
7
7