expensify-common 2.0.1 → 2.0.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.
package/dist/API.js CHANGED
@@ -12,6 +12,7 @@ const underscore_1 = __importDefault(require("underscore"));
12
12
  // Use this deferred lib so we don't have a dependency on jQuery (so we can use this module in mobile)
13
13
  const simply_deferred_1 = require("simply-deferred");
14
14
  const APIDeferred_1 = __importDefault(require("./APIDeferred"));
15
+ const utils_1 = require("./utils");
15
16
  /**
16
17
  * @param {Network} network
17
18
  * @param {Object} [args]
@@ -46,7 +47,7 @@ function API(network, args) {
46
47
  network
47
48
  .get('/revision.txt')
48
49
  .done((codeRevision) => {
49
- if (codeRevision.trim() === window.CODE_REVISION) {
50
+ if ((0, utils_1.isWindowAvailable)() && codeRevision.trim() === window.CODE_REVISION) {
50
51
  console.debug('Code revision is up to date');
51
52
  promise.resolve();
52
53
  }
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("./utils");
3
4
  const BROWSERS = {
4
5
  EDGE: 'Edge',
5
6
  CHROME: 'Chrome',
@@ -13,6 +14,9 @@ const MOBILE_PLATFORMS = {
13
14
  android: 'android',
14
15
  };
15
16
  function searchString() {
17
+ if (!(0, utils_1.isWindowAvailable)() || !(0, utils_1.isNavigatorAvailable)()) {
18
+ return '';
19
+ }
16
20
  const data = [
17
21
  {
18
22
  string: navigator.userAgent,
@@ -71,6 +75,9 @@ function searchString() {
71
75
  return '';
72
76
  }
73
77
  function getMobileDevice() {
78
+ if (!(0, utils_1.isNavigatorAvailable)() || !navigator.userAgent) {
79
+ return '';
80
+ }
74
81
  const data = [
75
82
  {
76
83
  devices: ['iPhone', 'iPad', 'iPod'],
package/dist/Log.js CHANGED
@@ -8,6 +8,7 @@ const underscore_1 = __importDefault(require("underscore"));
8
8
  const API_1 = __importDefault(require("./API"));
9
9
  const Network_1 = __importDefault(require("./Network"));
10
10
  const Logger_1 = __importDefault(require("./Logger"));
11
+ const utils_1 = require("./utils");
11
12
  /**
12
13
  * Network interface for logger.
13
14
  *
@@ -26,7 +27,7 @@ function serverLoggingCallback(logger, params) {
26
27
  * @param {String} message
27
28
  */
28
29
  function clientLoggingCallback(message) {
29
- if (typeof window.g_printableReport !== 'undefined' && window.g_printableReport === true) {
30
+ if ((0, utils_1.isWindowAvailable)() && typeof window.g_printableReport !== 'undefined' && window.g_printableReport === true) {
30
31
  return;
31
32
  }
32
33
  if (window.console && underscore_1.default.isFunction(console.log)) {
@@ -36,5 +37,5 @@ function clientLoggingCallback(message) {
36
37
  exports.default = new Logger_1.default({
37
38
  serverLoggingCallback,
38
39
  clientLoggingCallback,
39
- isDebug: window.DEBUG,
40
+ isDebug: (0, utils_1.isWindowAvailable)() ? window.DEBUG : false,
40
41
  });
package/dist/Network.js CHANGED
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const jquery_1 = __importDefault(require("jquery"));
7
7
  const underscore_1 = __importDefault(require("underscore"));
8
+ const utils_1 = require("./utils");
8
9
  /**
9
10
  * Adds our API command to the URL so the API call is more easily identified in the
10
11
  * network tab of the JS console
@@ -38,9 +39,11 @@ function Network(endpoint) {
38
39
  throw new Error('Cannot instantiate Network without an url endpoint');
39
40
  }
40
41
  // Attach a listener to the event indicating that we're leaving a page
41
- window.onbeforeunload = () => {
42
- isNavigatingAway = true;
43
- };
42
+ if ((0, utils_1.isWindowAvailable)()) {
43
+ window.onbeforeunload = () => {
44
+ isNavigatingAway = true;
45
+ };
46
+ }
44
47
  return {
45
48
  /**
46
49
  * @param {String} url to fetch
package/dist/PubSub.js CHANGED
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const underscore_1 = __importDefault(require("underscore"));
7
7
  const has_1 = __importDefault(require("lodash/has"));
8
8
  const Log_1 = __importDefault(require("./Log"));
9
+ const utils_1 = require("./utils");
9
10
  /**
10
11
  * PubSub
11
12
  *
@@ -112,4 +113,4 @@ const PubSubModule = {
112
113
  });
113
114
  },
114
115
  };
115
- exports.default = window !== undefined && window.PubSub ? window.PubSub : PubSubModule;
116
+ exports.default = (0, utils_1.isWindowAvailable)() && window.PubSub ? window.PubSub : PubSubModule;
package/dist/index.d.ts CHANGED
@@ -13,7 +13,7 @@ export { default as PageEvent } from './PageEvent';
13
13
  export { default as PubSub } from './PubSub';
14
14
  export { default as ReportHistoryStore } from './ReportHistoryStore';
15
15
  export { default as Templates } from './Templates';
16
- export { default as Url } from './Url';
16
+ export * as Url from './Url';
17
17
  export { default as fastMerge } from './fastMerge';
18
18
  export { default as Str } from './str';
19
19
  export { default as TLD_REGEX } from './tlds';
package/dist/index.js CHANGED
@@ -62,8 +62,7 @@ var ReportHistoryStore_1 = require("./ReportHistoryStore");
62
62
  Object.defineProperty(exports, "ReportHistoryStore", { enumerable: true, get: function () { return __importDefault(ReportHistoryStore_1).default; } });
63
63
  var Templates_1 = require("./Templates");
64
64
  Object.defineProperty(exports, "Templates", { enumerable: true, get: function () { return __importDefault(Templates_1).default; } });
65
- var Url_1 = require("./Url");
66
- Object.defineProperty(exports, "Url", { enumerable: true, get: function () { return __importDefault(Url_1).default; } });
65
+ exports.Url = __importStar(require("./Url"));
67
66
  var fastMerge_1 = require("./fastMerge");
68
67
  Object.defineProperty(exports, "fastMerge", { enumerable: true, get: function () { return __importDefault(fastMerge_1).default; } });
69
68
  var str_1 = require("./str");
@@ -5,7 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const underscore_1 = __importDefault(require("underscore"));
7
7
  const PubSub_1 = __importDefault(require("../PubSub"));
8
- const PubSub = window.PubSub || PubSub_1.default;
8
+ const utils_1 = require("../utils");
9
+ const PubSub = ((0, utils_1.isWindowAvailable)() && window.PubSub) || PubSub_1.default;
9
10
  /**
10
11
  * This mixin sets up automatic PubSub bindings which will be removed when
11
12
  * the component is unmounted.
@@ -23,9 +23,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
23
23
  * return <Div extraClasses={['large', 'primary']} />;
24
24
  * }
25
25
  */
26
+ const utils_1 = require("../utils");
26
27
  exports.default = {
27
28
  propTypes: {
28
- extraClasses: window.PropTypes.oneOfType([window.PropTypes.string, window.PropTypes.array, window.PropTypes.object]),
29
+ extraClasses: (0, utils_1.isWindowAvailable)() && window.PropTypes.oneOfType([window.PropTypes.string, window.PropTypes.array, window.PropTypes.object]),
29
30
  },
30
31
  UNSAFE_componentWillReceiveProps(nextProps) {
31
32
  this.setState({ classes: React.classNames(this.defaultClasses || [], nextProps.extraClasses) });
@@ -0,0 +1,5 @@
1
+ /** Checks if the `window` global object is available. */
2
+ declare function isWindowAvailable(): boolean;
3
+ /** Checks if the `navigator` global object is available. */
4
+ declare function isNavigatorAvailable(): boolean;
5
+ export { isWindowAvailable, isNavigatorAvailable };
package/dist/utils.js ADDED
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isNavigatorAvailable = exports.isWindowAvailable = void 0;
4
+ /** Checks if the `window` global object is available. */
5
+ function isWindowAvailable() {
6
+ return typeof window !== 'undefined';
7
+ }
8
+ exports.isWindowAvailable = isWindowAvailable;
9
+ /** Checks if the `navigator` global object is available. */
10
+ function isNavigatorAvailable() {
11
+ return typeof navigator !== 'undefined';
12
+ }
13
+ exports.isNavigatorAvailable = isNavigatorAvailable;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expensify-common",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "author": "Expensify, Inc.",
5
5
  "description": "Expensify libraries and components shared across different repos",
6
6
  "homepage": "https://expensify.com",