react-native-mosquito-transport 0.0.28 → 0.0.29

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-mosquito-transport",
3
- "version": "0.0.28",
3
+ "version": "0.0.29",
4
4
  "description": "React native javascript sdk for mosquito-transport (https://github.com/brainbehindx/mosquito-transport)",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -42,7 +42,7 @@
42
42
  "peerDependencies": {
43
43
  "react": "*",
44
44
  "react-native": "*",
45
- "react-native-file-access": "*",
45
+ "react-native-fs": "*",
46
46
  "react-native-sha256": "*",
47
47
  "react-native-sqlite-storage": "*"
48
48
  },
@@ -1,28 +1,28 @@
1
1
  import { Platform } from "react-native";
2
2
  import { Buffer } from 'buffer';
3
3
  import { deserialize, serialize } from 'entity-serializer';
4
- import { Dirs, FileSystem } from 'react-native-file-access';
4
+ import { writeFile, mkdir, MainBundlePath, readFile, unlink } from "react-native-fs";
5
5
 
6
6
  const MAX_INLINE_BLOB = 1024;
7
7
 
8
- const DIR_PATH = `${Platform.OS === 'android' ? Dirs.DatabaseDir : Dirs.MainBundleDir}/MOSQUITO`;
8
+ const DIR_PATH = `${Platform.OS === 'android' ? DocumentDirectoryPath.split('/').slice(0, -1).join('/').concat('/database') : MainBundlePath}/MOSQUITO`;
9
9
  const resolvePath = (path = '') => `${DIR_PATH}/${path.startsWith('/') ? path : '/' + path}`;
10
10
 
11
- const DIR_CREATION_PROMISE = FileSystem.mkdir(DIR_PATH).catch(() => null);
11
+ const DIR_CREATION_PROMISE = mkdir(DIR_PATH).catch(() => null);
12
12
 
13
13
  const fsWrite = async (path, data) => {
14
14
  await DIR_CREATION_PROMISE;
15
- return FileSystem.writeFile(resolvePath(path), data instanceof Buffer ? data.toString('base64') : data, 'base64');
15
+ return writeFile(resolvePath(path), data instanceof Buffer ? data.toString('base64') : data, 'base64');
16
16
  }
17
17
 
18
18
  const fsRead = async (path) => {
19
19
  await DIR_CREATION_PROMISE;
20
- return Buffer.from(await FileSystem.readFile(resolvePath(path), 'base64'), 'base64');
20
+ return Buffer.from(await readFile(resolvePath(path), 'base64'), 'base64');
21
21
  }
22
22
 
23
23
  export const getStoreID = (db_filename, table, primary_key) => `${table}_${primary_key}_${db_filename}.blob`;
24
24
 
25
- export const deleteBigData = (store_id) => FileSystem.unlink(resolvePath(store_id));
25
+ export const deleteBigData = (store_id) => unlink(resolvePath(store_id));
26
26
 
27
27
  export const handleBigData = async (store_id, data) => {
28
28
  const bufData = serialize(data);
@@ -11,6 +11,7 @@ export const listenReachableServer = (callback, projectUrl) => {
11
11
  let lastValue;
12
12
  return ServerReachableListener.listenTo(projectUrl, t => {
13
13
  if (typeof t === 'boolean' && t !== lastValue) callback?.(t);
14
+ lastValue = t;
14
15
  }, true);
15
16
  };
16
17
 
package/src/index.d.ts CHANGED
@@ -427,7 +427,7 @@ interface DocumentWriteValue {
427
427
 
428
428
  interface RNMTAuth {
429
429
  customSignin: (email: string, password: string) => Promise<SigninResult>;
430
- customSignup: (email: string, password: string, name?: string, metadata?: Object) => Promise<SigninResult>;
430
+ customSignup: (email: string, password: string, name?: string, metadata?: Object) => Promise<SignupResult>;
431
431
  googleSignin: (token: string) => Promise<SignupResult>;
432
432
  appleSignin: () => Promise<SignupResult>;
433
433
  facebookSignin: () => Promise<SignupResult>;
package/src/index.js CHANGED
@@ -21,7 +21,8 @@ const {
21
21
  _listenDocument,
22
22
  _startDisconnectWriteTask,
23
23
  _cancelDisconnectWriteTask,
24
- _listenUserVerification
24
+ _listenUserVerification,
25
+ _areYouOk
25
26
  } = EngineApi;
26
27
 
27
28
  // https://socket.io/docs/v3/emit-cheatsheet/#reserved-events
@@ -73,12 +74,7 @@ class RNMT {
73
74
  _from_base: true
74
75
  }
75
76
  });
76
-
77
- socket.on('_signal_signout', () => {
78
- this.auth().signOut();
79
- });
80
-
81
- socket.on('connect', () => {
77
+ const onConnect = () => {
82
78
  isConnected = true;
83
79
  Scoped.IS_CONNECTED[projectUrl] = true;
84
80
  if (queuedToken) updateMountedToken(queuedToken.token);
@@ -86,12 +82,28 @@ class RNMT {
86
82
  awaitStore().then(() => {
87
83
  trySendPendingWrite(projectUrl);
88
84
  });
89
- });
90
-
91
- socket.on('disconnect', () => {
85
+ };
86
+ const onDisconnect = () => {
92
87
  isConnected = false;
93
88
  Scoped.IS_CONNECTED[projectUrl] = false;
94
89
  ServerReachableListener.dispatch(projectUrl, false);
90
+ }
91
+
92
+ const manualCheckConnection = () =>
93
+ fetch(_areYouOk(projectUrl), { cache: 'no-cache' }).then(async r => {
94
+ if ((await r.json()).status === 'yes') {
95
+ onConnect();
96
+ } else throw null;
97
+ }).catch(onDisconnect);
98
+ manualCheckConnection();
99
+
100
+ socket.on('_signal_signout', () => {
101
+ this.auth().signOut();
102
+ });
103
+
104
+ socket.on('connect', onConnect);
105
+ socket.on('disconnect', () => {
106
+ manualCheckConnection();
95
107
  });
96
108
 
97
109
  const updateMountedToken = (token) => {
@@ -220,7 +220,8 @@ const doCustomSignup = (builder, email, password, name, metadata) => new Promise
220
220
  resolve({
221
221
  user: parseToken(r.result.token),
222
222
  token: r.result.token,
223
- refreshToken: r.result.refreshToken
223
+ refreshToken: r.result.refreshToken,
224
+ isNewUser: !!r.result.isNewUser
224
225
  });
225
226
  await injectFreshToken(builder, r.result);
226
227
  revokeAuthIntance(builder, thisAuthStore);