react-native-mosquito-transport 0.0.23 → 0.0.24

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.24",
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",
@@ -33,9 +33,9 @@
33
33
  "entity-serializer": "^1.0.2",
34
34
  "guard-object": "^1.1.4",
35
35
  "lodash": "^4.17.21",
36
- "react-native-fs": "^2.20.0",
36
+ "react-native-file-access": "^3.1.1",
37
37
  "react-native-get-random-values": "^1.9.0",
38
- "react-native-hash": "^3.0.3",
38
+ "react-native-sha256": "^1.4.10",
39
39
  "simplify-error": "^1.0.1",
40
40
  "socket.io-client": "^4.6.2",
41
41
  "subscription-listener": "^1.1.2",
@@ -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);
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
  };