expensify-common 2.0.1 → 2.0.3
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 +2 -1
- package/dist/BrowserDetect.js +7 -0
- package/dist/ExpensiMark.d.ts +1 -1
- package/dist/ExpensiMark.js +6 -6
- package/dist/Log.js +3 -2
- package/dist/Network.js +6 -3
- package/dist/PubSub.js +2 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -2
- package/dist/mixins/PubSub.js +2 -1
- package/dist/mixins/extraClasses.js +2 -1
- package/dist/utils.d.ts +5 -0
- package/dist/utils.js +13 -0
- package/package.json +1 -1
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
|
}
|
package/dist/BrowserDetect.js
CHANGED
|
@@ -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/ExpensiMark.d.ts
CHANGED
package/dist/ExpensiMark.js
CHANGED
|
@@ -453,7 +453,7 @@ class ExpensiMark {
|
|
|
453
453
|
name: 'reportMentions',
|
|
454
454
|
regex: /<mention-report reportID="(\d+)" *\/>/gi,
|
|
455
455
|
replacement: (match, g1, offset, string, extras) => {
|
|
456
|
-
const reportToNameMap = extras.
|
|
456
|
+
const reportToNameMap = extras.reportIDToName;
|
|
457
457
|
if (!reportToNameMap || !reportToNameMap[g1]) {
|
|
458
458
|
Log_1.default.alert('[ExpensiMark] Missing report name', { reportID: g1 });
|
|
459
459
|
return '#Hidden';
|
|
@@ -466,12 +466,12 @@ class ExpensiMark {
|
|
|
466
466
|
regex: /(?:<mention-user accountID="(\d+)" *\/>)|(?:<mention-user>(.*?)<\/mention-user>)/gi,
|
|
467
467
|
replacement: (match, g1, g2, offset, string, extras) => {
|
|
468
468
|
if (g1) {
|
|
469
|
-
const accountToNameMap = extras.
|
|
469
|
+
const accountToNameMap = extras.accountIDToName;
|
|
470
470
|
if (!accountToNameMap || !accountToNameMap[g1]) {
|
|
471
471
|
Log_1.default.alert('[ExpensiMark] Missing account name', { accountID: g1 });
|
|
472
472
|
return '@Hidden';
|
|
473
473
|
}
|
|
474
|
-
return `@${extras.
|
|
474
|
+
return `@${extras.accountIDToName[g1]}`;
|
|
475
475
|
}
|
|
476
476
|
return str_1.default.removeSMSDomain(g2);
|
|
477
477
|
},
|
|
@@ -522,7 +522,7 @@ class ExpensiMark {
|
|
|
522
522
|
name: 'reportMentions',
|
|
523
523
|
regex: /<mention-report reportID="(\d+)" *\/>/gi,
|
|
524
524
|
replacement: (match, g1, offset, string, extras) => {
|
|
525
|
-
const reportToNameMap = extras.
|
|
525
|
+
const reportToNameMap = extras.reportIDToName;
|
|
526
526
|
if (!reportToNameMap || !reportToNameMap[g1]) {
|
|
527
527
|
Log_1.default.alert('[ExpensiMark] Missing report name', { reportID: g1 });
|
|
528
528
|
return '#Hidden';
|
|
@@ -534,12 +534,12 @@ class ExpensiMark {
|
|
|
534
534
|
name: 'userMention',
|
|
535
535
|
regex: /<mention-user accountID="(\d+)" *\/>/gi,
|
|
536
536
|
replacement: (match, g1, offset, string, extras) => {
|
|
537
|
-
const accountToNameMap = extras.
|
|
537
|
+
const accountToNameMap = extras.accountIDToName;
|
|
538
538
|
if (!accountToNameMap || !accountToNameMap[g1]) {
|
|
539
539
|
Log_1.default.alert('[ExpensiMark] Missing account name', { accountID: g1 });
|
|
540
540
|
return '@Hidden';
|
|
541
541
|
}
|
|
542
|
-
return `@${extras.
|
|
542
|
+
return `@${extras.accountIDToName[g1]}`;
|
|
543
543
|
},
|
|
544
544
|
},
|
|
545
545
|
{
|
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
|
-
|
|
42
|
-
|
|
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 =
|
|
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
|
|
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
|
-
|
|
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");
|
package/dist/mixins/PubSub.js
CHANGED
|
@@ -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
|
|
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) });
|
package/dist/utils.d.ts
ADDED
|
@@ -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;
|