dreaction-react-native 1.7.0 → 1.7.2

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.
@@ -56,7 +56,7 @@ exports.ConfigDialog = react_1.default.memo((props) => {
56
56
  });
57
57
  }, []);
58
58
  const handleConfirm = () => {
59
- const host = (0, parseURL_1.getHostFromUrl)(inputValue);
59
+ const host = (0, parseURL_1.getHostWithPortFromUrl)(inputValue);
60
60
  dreaction_1.dreaction.asyncStorageHandler?.setItem(LOCAL_CACHE_HOST_NAME, host);
61
61
  onConfirm(host);
62
62
  };
@@ -6,4 +6,10 @@
6
6
  * @returns {string} host of given URL or throws
7
7
  */
8
8
  export declare function getHostFromUrl(url: string): string;
9
+ /**
10
+ * Extract host:port from URL
11
+ * @param url URL string
12
+ * @returns host:port string or throws if invalid
13
+ */
14
+ export declare function getHostWithPortFromUrl(url: string): string;
9
15
  //# sourceMappingURL=parseURL.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parseURL.d.ts","sourceRoot":"","sources":["../../src/helpers/parseURL.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,UAUzC"}
1
+ {"version":3,"file":"parseURL.d.ts","sourceRoot":"","sources":["../../src/helpers/parseURL.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,UAUzC;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,UAWjD"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getHostFromUrl = getHostFromUrl;
4
+ exports.getHostWithPortFromUrl = getHostWithPortFromUrl;
4
5
  /**
5
6
  * Given a valid http(s) URL, the host for the given URL
6
7
  * is returned.
@@ -19,3 +20,18 @@ function getHostFromUrl(url) {
19
20
  throw new Error("Invalid URL - host not found");
20
21
  return host;
21
22
  }
23
+ /**
24
+ * Extract host:port from URL
25
+ * @param url URL string
26
+ * @returns host:port string or throws if invalid
27
+ */
28
+ function getHostWithPortFromUrl(url) {
29
+ const hostWithPort = url
30
+ .replace(/^(?:https?:\/\/)?/, '')
31
+ .split(/[/?#]/)[0]
32
+ .trim();
33
+ if (!hostWithPort) {
34
+ throw new Error('Invalid URL - host not found');
35
+ }
36
+ return hostWithPort;
37
+ }
@@ -4,6 +4,7 @@ import { DReactionCore } from 'dreaction-client-core';
4
4
  */
5
5
  declare const trackGlobalLogs: () => (dreaction: DReactionCore) => {
6
6
  onConnect: () => void;
7
+ onDisconnect: () => void;
7
8
  };
8
9
  export default trackGlobalLogs;
9
10
  //# sourceMappingURL=trackGlobalLogs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"trackGlobalLogs.d.ts","sourceRoot":"","sources":["../../src/plugins/trackGlobalLogs.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,aAAa,EAGd,MAAM,uBAAuB,CAAC;AAE/B;;GAEG;AACH,QAAA,MAAM,eAAe,oBAAqB,aAAa;;CA4BtD,CAAC;AAEF,eAAe,eAAe,CAAC"}
1
+ {"version":3,"file":"trackGlobalLogs.d.ts","sourceRoot":"","sources":["../../src/plugins/trackGlobalLogs.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,aAAa,EAGd,MAAM,uBAAuB,CAAC;AAE/B;;GAEG;AACH,QAAA,MAAM,eAAe,oBAAqB,aAAa;;;CAuCtD,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -7,25 +7,36 @@ const dreaction_client_core_1 = require("dreaction-client-core");
7
7
  const trackGlobalLogs = () => (dreaction) => {
8
8
  (0, dreaction_client_core_1.assertHasLoggerPlugin)(dreaction);
9
9
  const client = dreaction;
10
+ const originalConsoleLog = console.log;
11
+ const originalConsoleWarn = console.warn;
12
+ const originalConsoleDebug = console.debug;
13
+ const originalConsoleInfo = console.info;
10
14
  return {
11
15
  onConnect: () => {
12
- const originalConsoleLog = console.log;
13
16
  console.log = (...args) => {
14
17
  originalConsoleLog(...args);
15
18
  client.log(...args);
16
19
  };
17
- const originalConsoleWarn = console.warn;
20
+ console.info = (...args) => {
21
+ originalConsoleInfo(...args);
22
+ client.log(...args);
23
+ };
18
24
  console.warn = (...args) => {
19
25
  originalConsoleWarn(...args);
20
26
  client.warn(args[0]);
21
27
  };
22
- const originalConsoleDebug = console.debug;
23
28
  console.debug = (...args) => {
24
29
  originalConsoleDebug(...args);
25
30
  client.debug(args[0]);
26
31
  };
27
32
  // console.error is taken care of by ./trackGlobalErrors.ts
28
33
  },
34
+ onDisconnect: () => {
35
+ console.log = originalConsoleLog;
36
+ console.warn = originalConsoleWarn;
37
+ console.debug = originalConsoleDebug;
38
+ console.info = originalConsoleInfo;
39
+ }
29
40
  };
30
41
  };
31
42
  exports.default = trackGlobalLogs;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dreaction-react-native",
3
- "version": "1.7.0",
3
+ "version": "1.7.2",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "main": "lib/index.js",
@@ -15,8 +15,8 @@
15
15
  "author": "moonrailgun <moonrailgun@gmail.com>",
16
16
  "license": "MIT",
17
17
  "dependencies": {
18
- "dreaction-protocol": "1.0.8",
19
- "dreaction-client-core": "1.2.0"
18
+ "dreaction-client-core": "1.2.0",
19
+ "dreaction-protocol": "1.0.8"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@react-native-async-storage/async-storage": "^2.1.0",
@@ -9,7 +9,7 @@ import {
9
9
  } from 'react-native';
10
10
  import { getHost } from '../helpers/getHost';
11
11
  import { dreaction } from '../dreaction';
12
- import { getHostFromUrl } from '../helpers/parseURL';
12
+ import { getHostWithPortFromUrl } from '../helpers/parseURL';
13
13
 
14
14
  const LOCAL_CACHE_HOST_NAME = '__dreaction-react-native-host';
15
15
 
@@ -36,7 +36,7 @@ export const ConfigDialog: React.FC<ConfigDialogProps> = React.memo((props) => {
36
36
  }, []);
37
37
 
38
38
  const handleConfirm = () => {
39
- const host = getHostFromUrl(inputValue);
39
+ const host = getHostWithPortFromUrl(inputValue);
40
40
  dreaction.asyncStorageHandler?.setItem(LOCAL_CACHE_HOST_NAME, host);
41
41
  onConfirm(host);
42
42
  };
@@ -17,3 +17,21 @@ export function getHostFromUrl(url: string) {
17
17
 
18
18
  return host
19
19
  }
20
+
21
+ /**
22
+ * Extract host:port from URL
23
+ * @param url URL string
24
+ * @returns host:port string or throws if invalid
25
+ */
26
+ export function getHostWithPortFromUrl(url: string) {
27
+ const hostWithPort = url
28
+ .replace(/^(?:https?:\/\/)?/, '')
29
+ .split(/[/?#]/)[0]
30
+ .trim();
31
+
32
+ if (!hostWithPort) {
33
+ throw new Error('Invalid URL - host not found');
34
+ }
35
+
36
+ return hostWithPort;
37
+ }
@@ -14,21 +14,26 @@ const trackGlobalLogs = () => (dreaction: DReactionCore) => {
14
14
  const client = dreaction as DReactionCore &
15
15
  InferFeatures<DReactionCore, LoggerPlugin>;
16
16
 
17
+ const originalConsoleLog = console.log;
18
+ const originalConsoleWarn = console.warn;
19
+ const originalConsoleDebug = console.debug;
20
+ const originalConsoleInfo = console.info;
21
+
17
22
  return {
18
23
  onConnect: () => {
19
- const originalConsoleLog = console.log;
20
24
  console.log = (...args: Parameters<typeof console.log>) => {
21
25
  originalConsoleLog(...args);
22
26
  client.log(...args);
23
27
  };
24
-
25
- const originalConsoleWarn = console.warn;
28
+ console.info = (...args: Parameters<typeof console.info>) => {
29
+ originalConsoleInfo(...args);
30
+ client.log(...args);
31
+ };
26
32
  console.warn = (...args: Parameters<typeof console.warn>) => {
27
33
  originalConsoleWarn(...args);
28
34
  client.warn(args[0]);
29
35
  };
30
36
 
31
- const originalConsoleDebug = console.debug;
32
37
  console.debug = (...args: Parameters<typeof console.debug>) => {
33
38
  originalConsoleDebug(...args);
34
39
  client.debug(args[0]);
@@ -36,6 +41,12 @@ const trackGlobalLogs = () => (dreaction: DReactionCore) => {
36
41
 
37
42
  // console.error is taken care of by ./trackGlobalErrors.ts
38
43
  },
44
+ onDisconnect: () => {
45
+ console.log = originalConsoleLog;
46
+ console.warn = originalConsoleWarn;
47
+ console.debug = originalConsoleDebug;
48
+ console.info = originalConsoleInfo;
49
+ }
39
50
  } satisfies Plugin<DReactionCore>;
40
51
  };
41
52