react-native-mosquito-transport 0.0.30 → 0.0.32

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.30",
3
+ "version": "0.0.32",
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",
@@ -27,19 +27,18 @@
27
27
  },
28
28
  "homepage": "https://github.com/brainbehindx/react-native-mosquito-transport#readme",
29
29
  "dependencies": {
30
- "@turf/turf": "^7.1.0",
30
+ "@turf/turf": "^7.2.0",
31
31
  "bson": "^6.8.0",
32
32
  "buffer": "^6.0.3",
33
33
  "entity-serializer": "^1.0.3",
34
34
  "guard-object": "^1.1.4",
35
35
  "lodash": "^4.17.21",
36
36
  "simplify-error": "^1.0.1",
37
- "socket.io-client": "^4.6.2",
37
+ "socket.io-client": "^4.8.1",
38
38
  "subscription-listener": "^1.1.2",
39
39
  "tweetnacl": "^1.0.3"
40
40
  },
41
41
  "peerDependencies": {
42
- "react": "*",
43
42
  "react-native": "*",
44
43
  "react-native-fs": "*",
45
44
  "react-native-sha256": "*",
package/src/index.d.ts CHANGED
@@ -146,6 +146,10 @@ interface RNMTSocket {
146
146
  on: (route: string, callback?: () => any) => void;
147
147
  once: (route: string, callback?: () => any) => void;
148
148
  destroy: () => void;
149
+ /**
150
+ * Whether the socket is currently disconnected
151
+ */
152
+ disconnected: boolean;
149
153
  }
150
154
 
151
155
  interface BatchWriteValue {
@@ -279,6 +283,11 @@ interface DocumentError extends ErrorResponse {
279
283
 
280
284
  interface FetchHttpConfig {
281
285
  retrieval?: GetConfig['retrieval'];
286
+ /**
287
+ * disable sending authentication token along with this request
288
+ *
289
+ * Defaults to true when either `rawApproach` is true or the request url is absolute otherwise false
290
+ */
282
291
  disableAuth?: boolean;
283
292
  enableMinimizer?: boolean;
284
293
  rawApproach?: boolean;
@@ -311,7 +320,7 @@ interface WriteConfig {
311
320
  delivery?: Delievery;
312
321
  }
313
322
 
314
- type Retrieval = 'sticky' | 'sticky-no-await' | 'sticky-reload' | 'default' | 'cache-no-await' | 'no-cache-no-await' | 'no-cache-await';
323
+ type Retrieval = 'sticky' | 'sticky-no-await' | 'sticky-reload' | 'default' | 'cache-no-await' | 'no-cache-no-await' | 'no-cache-await' | 'cache-await';
315
324
 
316
325
  interface GetConfig {
317
326
  excludeFields?: string | string[];
package/src/index.js CHANGED
@@ -321,8 +321,8 @@ class RNMT {
321
321
  lastTokenStatus = status || false;
322
322
  }, projectUrl);
323
323
  }
324
- // TODO: disconnected
325
- return {
324
+
325
+ const resultant = {
326
326
  timeout: (timeout) => {
327
327
  if (timeout !== undefined && !Validator.POSITIVE_INTEGER(timeout))
328
328
  throw `expected a positive integer for timeout but got ${timeout}`;
@@ -378,7 +378,17 @@ class RNMT {
378
378
  if (socket) socket.close();
379
379
  socketListenerList = [];
380
380
  }
381
- }
381
+ };
382
+
383
+ Object.defineProperty(resultant, 'disconnected', {
384
+ get() {
385
+ return socket.disconnected;
386
+ },
387
+ enumerable: true,
388
+ configurable: false
389
+ });
390
+
391
+ return resultant;
382
392
  }
383
393
  };
384
394
 
@@ -48,7 +48,7 @@ export const mfetch = async (input = '', init, config) => {
48
48
  const { retrieval = RETRIEVAL.DEFAULT, enableMinimizer, rawApproach } = method || {};
49
49
  const isLink = Validator.LINK(input);
50
50
  const isBaseUrl = isLink || rawApproach;
51
- const disableAuth = method?.disableAuth || isBaseUrl;
51
+ const disableAuth = method?.disableAuth === undefined ? isBaseUrl : method?.disableAuth;
52
52
  const hasBody = body !== undefined;
53
53
  const shouldCache = (retrieval !== RETRIEVAL.DEFAULT || (config.disableCache === undefined ? !hasBody : !disableCache)) &&
54
54
  ![RETRIEVAL.NO_CACHE_NO_AWAIT, RETRIEVAL.NO_CACHE_AWAIT].includes(retrieval);
@@ -135,7 +135,7 @@ export const mfetch = async (input = '', init, config) => {
135
135
  if (!disableAuth && await getReachableServer(projectUrl))
136
136
  await awaitRefreshToken(projectUrl);
137
137
 
138
- const mtoken = Scoped.AuthJWTToken[projectUrl];
138
+ const mtoken = disableAuth ? undefined : Scoped.AuthJWTToken[projectUrl];
139
139
  const initType = rawHeader['content-type'];
140
140
  const encodeBody = initType === undefined && hasBody && !isBaseUrl;
141
141
 
@@ -157,13 +157,13 @@ export const mfetch = async (input = '', init, config) => {
157
157
  } : encodeBody
158
158
  ? { 'content-type': 'request/buffer', 'entity-encoded': '1' }
159
159
  : {},
160
- ...(disableAuth || !mtoken || uglified || isBaseUrl) ? {} : { mtoken }
160
+ ...(!mtoken || uglified) ? {} : { mtoken }
161
161
  }
162
162
  });
163
163
  const { ok, type, status, statusText, redirected, url, headers, size } = f;
164
164
  const simple = headers.get('simple_error');
165
165
 
166
- if (!isBaseUrl && simple) throw { simpleError: JSON.parse(simple) };
166
+ if (!isLink && simple) throw { simpleError: JSON.parse(simple) };
167
167
 
168
168
  const base64 = uglified ?
169
169
  Buffer.from(await deserializeE2E(await f.arrayBuffer(), serverE2E_PublicKey, privateKey)).toString('base64') :