react-native-mosquito-transport 0.0.23 → 0.0.25

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.23",
3
+ "version": "0.0.25",
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",
@@ -30,12 +30,10 @@
30
30
  "@turf/turf": "^7.1.0",
31
31
  "bson": "^6.8.0",
32
32
  "buffer": "^6.0.3",
33
- "entity-serializer": "^1.0.2",
33
+ "entity-serializer": "^1.0.3",
34
34
  "guard-object": "^1.1.4",
35
35
  "lodash": "^4.17.21",
36
- "react-native-fs": "^2.20.0",
37
36
  "react-native-get-random-values": "^1.9.0",
38
- "react-native-hash": "^3.0.3",
39
37
  "simplify-error": "^1.0.1",
40
38
  "socket.io-client": "^4.6.2",
41
39
  "subscription-listener": "^1.1.2",
@@ -43,9 +41,12 @@
43
41
  },
44
42
  "peerDependencies": {
45
43
  "react": "*",
46
- "react-native": "*"
44
+ "react-native": "*",
45
+ "react-native-file-access": "*",
46
+ "react-native-sha256": "*",
47
+ "react-native-sqlite-storage": "*"
47
48
  },
48
49
  "devDependencies": {
49
50
  "@types/react-native-sqlite-storage": "^6.0.5"
50
51
  }
51
- }
52
+ }
@@ -1,18 +1,28 @@
1
+ import { Platform } from "react-native";
1
2
  import { Buffer } from 'buffer';
2
3
  import { deserialize, serialize } from 'entity-serializer';
3
- import { DocumentDirectoryPath, readFile, unlink, writeFile } from 'react-native-fs';
4
+ import { Dirs, FileSystem } from 'react-native-file-access';
4
5
 
5
6
  const MAX_INLINE_BLOB = 1024;
6
7
 
7
- const resolvePath = (path = '') => `file:///${DocumentDirectoryPath}${path.startsWith('/') ? path : '/' + path}`;
8
+ const DIR_PATH = `${Platform.OS === 'android' ? Dirs.DatabaseDir : Dirs.MainBundleDir}/MOSQUITO`;
9
+ const resolvePath = (path = '') => `${DIR_PATH}/${path.startsWith('/') ? path : '/' + path}`;
8
10
 
9
- const fsWrite = (path, data) => writeFile(resolvePath(path), data instanceof Buffer ? data.toString('base64') : data);
11
+ const DIR_CREATION_PROMISE = FileSystem.mkdir(DIR_PATH).catch(() => null);
10
12
 
11
- const fsRead = async (path) => Buffer.from(await readFile(resolvePath(path), 'base64'), 'base64');
13
+ const fsWrite = async (path, data) => {
14
+ await DIR_CREATION_PROMISE;
15
+ return FileSystem.writeFile(resolvePath(path), data instanceof Buffer ? data.toString('base64') : data, 'base64');
16
+ }
17
+
18
+ const fsRead = async (path) => {
19
+ await DIR_CREATION_PROMISE;
20
+ return Buffer.from(await FileSystem.readFile(resolvePath(path), 'base64'), 'base64');
21
+ }
12
22
 
13
23
  export const getStoreID = (db_filename, table, primary_key) => `${table}_${primary_key}_${db_filename}.blob`;
14
24
 
15
- export const deleteBigData = (store_id) => unlink(resolvePath(store_id));
25
+ export const deleteBigData = (store_id) => FileSystem.unlink(resolvePath(store_id));
16
26
 
17
27
  export const handleBigData = async (store_id, data) => {
18
28
  const bufData = serialize(data);
@@ -3,7 +3,7 @@ import { ServerReachableListener } from "./listeners";
3
3
  import naclPkg from 'tweetnacl';
4
4
  import getLodash from "lodash/get";
5
5
  import { deserialize, serialize } from "entity-serializer";
6
- import { CONSTANTS, JSHash } from 'react-native-hash';
6
+ import { sha256 } from 'react-native-sha256';
7
7
 
8
8
  const { box, randomBytes } = naclPkg;
9
9
 
@@ -65,7 +65,7 @@ export function sortArrayByObjectKey(arr = [], key) {
65
65
  };
66
66
 
67
67
  export async function niceHash(str = '') {
68
- const hash = await JSHash(str, CONSTANTS.HashAlgorithms.md5);
68
+ const hash = await sha256(str);
69
69
  if (hash.length > str.length) return encodeBinary(str);
70
70
  return hash;
71
71
  };
@@ -114,7 +114,7 @@ export const useSqliteLinearAccessId = (builder, access_id, node) => async (task
114
114
  try {
115
115
  resolve(await task(sqlite, db_filename));
116
116
  } catch (error) {
117
- console.error('useSqliteLinearAccessId err:', error);
117
+ console.error('useSqliteLinearAccessId err:', error, ' builder:', builder);
118
118
  reject(error);
119
119
  } finally {
120
120
  if (Scoped.linearSqliteProcess[node][nodeId] === thisPromise)