expensify-common 1.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/README.md +15 -6
- package/dist/API.d.ts +11 -0
- package/{lib/API.jsx → dist/API.js} +230 -165
- package/dist/APIDeferred.d.ts +7 -0
- package/{lib/APIDeferred.jsx → dist/APIDeferred.js} +35 -53
- package/dist/BrowserDetect.d.ts +19 -0
- package/dist/BrowserDetect.js +107 -0
- package/dist/CONST.d.ts +813 -0
- package/{lib/CONST.jsx → dist/CONST.js} +245 -167
- package/dist/Cookie.d.ts +68 -0
- package/{lib/Cookie.jsx → dist/Cookie.js} +23 -36
- package/dist/CredentialsWrapper.d.ts +32 -0
- package/dist/CredentialsWrapper.js +52 -0
- package/dist/Device.d.ts +8 -0
- package/dist/Device.js +15 -0
- package/dist/ExpenseRule.d.ts +39 -0
- package/{lib/ExpenseRule.jsx → dist/ExpenseRule.js} +12 -14
- package/dist/ExpensiMark.d.ts +142 -0
- package/dist/ExpensiMark.js +1026 -0
- package/dist/Func.d.ts +40 -0
- package/{lib/Func.jsx → dist/Func.js} +19 -25
- package/dist/Log.d.ts +3 -0
- package/dist/Log.js +41 -0
- package/dist/Logger.d.ts +77 -0
- package/dist/Logger.js +126 -0
- package/dist/Network.d.ts +6 -0
- package/{lib/Network.jsx → dist/Network.js} +48 -45
- package/dist/Num.d.ts +95 -0
- package/{lib/Num.jsx → dist/Num.js} +20 -40
- package/dist/PageEvent.d.ts +25 -0
- package/dist/PageEvent.js +28 -0
- package/dist/PubSub.d.ts +2 -0
- package/{lib/PubSub.jsx → dist/PubSub.js} +27 -39
- package/dist/ReportHistoryStore.d.ts +64 -0
- package/dist/ReportHistoryStore.js +261 -0
- package/dist/Templates.d.ts +2 -0
- package/{lib/Templates.jsx → dist/Templates.js} +33 -48
- package/dist/Url.d.ts +22 -0
- package/dist/Url.js +30 -0
- package/dist/components/CopyText.d.ts +45 -0
- package/{lib/components/CopyText.jsx → dist/components/CopyText.js} +16 -23
- package/dist/components/StepProgressBar.d.ts +22 -0
- package/dist/components/StepProgressBar.js +68 -0
- package/dist/components/form/element/combobox.d.ts +237 -0
- package/{lib → dist}/components/form/element/combobox.js +361 -516
- package/dist/components/form/element/dropdown.d.ts +35 -0
- package/dist/components/form/element/dropdown.js +66 -0
- package/dist/components/form/element/dropdownItem.d.ts +55 -0
- package/dist/components/form/element/dropdownItem.js +118 -0
- package/dist/components/form/element/onOffSwitch.d.ts +94 -0
- package/dist/components/form/element/onOffSwitch.js +195 -0
- package/dist/components/form/element/switch.d.ts +58 -0
- package/{lib → dist}/components/form/element/switch.js +29 -66
- package/dist/fastMerge.d.ts +9 -0
- package/dist/fastMerge.js +77 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +71 -0
- package/dist/jquery.expensifyIframify.d.ts +10 -0
- package/{lib → dist}/jquery.expensifyIframify.js +52 -93
- package/dist/mixins/PubSub.d.ts +20 -0
- package/{lib/mixins/PubSub.jsx → dist/mixins/PubSub.js} +12 -11
- package/dist/mixins/extraClasses.d.ts +8 -0
- package/{lib → dist}/mixins/extraClasses.js +8 -12
- package/dist/mixins/validationClasses.d.ts +12 -0
- package/dist/mixins/validationClasses.js +58 -0
- package/dist/str.d.ts +613 -0
- package/{lib → dist}/str.js +176 -160
- package/dist/tlds.d.ts +2 -0
- package/dist/tlds.js +4 -0
- package/dist/utils.d.ts +5 -0
- package/dist/utils.js +13 -0
- package/package.json +47 -18
- package/.editorconfig +0 -34
- package/.eslintrc.js +0 -11
- package/.github/CODEOWNERS +0 -2
- package/.github/CONTRIBUTING.md +0 -163
- package/.github/ISSUE_TEMPLATE.md +0 -3
- package/.github/PULL_REQUEST_TEMPLATE.md +0 -14
- package/.github/workflows/cla.yml +0 -39
- package/.github/workflows/lint.yml +0 -29
- package/.github/workflows/test.yml +0 -29
- package/CLA.md +0 -20
- package/Gruntfile.js +0 -13
- package/__tests__/ExpensiMark-test.js +0 -340
- package/__tests__/Logger-test.js +0 -55
- package/__tests__/Str-test.js +0 -53
- package/babel.config.js +0 -12
- package/grunt/configloader.js +0 -17
- package/grunt/configs/chokidar.js +0 -23
- package/grunt/configs/eslint.js +0 -15
- package/grunt/task/watch.js +0 -3
- package/grunt/taskloader.js +0 -25
- package/lib/BrowserDetect.jsx +0 -91
- package/lib/ExpensiMark.js +0 -253
- package/lib/Log.jsx +0 -36
- package/lib/Logger.jsx +0 -154
- package/lib/PageEvent.jsx +0 -23
- package/lib/ReportHistoryStore.jsx +0 -194
- package/lib/components/StepProgressBar.js +0 -49
- package/lib/components/form/element/dropdown.js +0 -90
- package/lib/components/form/element/dropdownItem.js +0 -178
- package/lib/components/form/element/onOffSwitch.jsx +0 -229
- package/lib/mixins/validationClasses.js +0 -23
- package/lib/tlds.jsx +0 -3
package/dist/Cookie.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
declare namespace _default {
|
|
2
|
+
export let NAME_LAST_PAGE: string;
|
|
3
|
+
export let NAME_LAST_REPORTS_PAGE: string;
|
|
4
|
+
export let NAME_STASHED_SUPPORT: string;
|
|
5
|
+
export let NAME_WEB_COOKIE: string;
|
|
6
|
+
export let NAME_EXPENSES_VIEW_MODE: string;
|
|
7
|
+
export let MOBILE_APP_VERSION: string;
|
|
8
|
+
export let TWO_FACTOR_DEVICE_TOKEN: string;
|
|
9
|
+
export { enabled };
|
|
10
|
+
export { remove };
|
|
11
|
+
export { get };
|
|
12
|
+
export { getJSON };
|
|
13
|
+
export { has };
|
|
14
|
+
export { getHelpLink };
|
|
15
|
+
export { set };
|
|
16
|
+
}
|
|
17
|
+
export default _default;
|
|
18
|
+
/**
|
|
19
|
+
* Detects if cookies are currently enabled in the browser
|
|
20
|
+
* by trying to create a cookie, see if it exists, and delete it afterwards again.
|
|
21
|
+
*
|
|
22
|
+
* @return {Boolean} True if cookies are enabled, otherwise false.
|
|
23
|
+
*/
|
|
24
|
+
declare function enabled(): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Deletes a cookie.
|
|
27
|
+
*
|
|
28
|
+
* @param {String} name The name of the cookie to delete.
|
|
29
|
+
*/
|
|
30
|
+
declare function remove(name: string): void;
|
|
31
|
+
/**
|
|
32
|
+
* Fetches the value of a cookie.
|
|
33
|
+
*
|
|
34
|
+
* @param {String} name The name of the cookie to fetch.
|
|
35
|
+
* @return {String|null} The value of the cookie.
|
|
36
|
+
*/
|
|
37
|
+
declare function get(name: string): string | null;
|
|
38
|
+
/**
|
|
39
|
+
* Parses a cookie value to JSON.
|
|
40
|
+
* Returns a default value specified by param or null.
|
|
41
|
+
*
|
|
42
|
+
* @param {String} name
|
|
43
|
+
* @param {Any|null} defaultValue
|
|
44
|
+
*
|
|
45
|
+
* @return {Any|null}
|
|
46
|
+
*/
|
|
47
|
+
declare function getJSON(name: string, defaultValue?: Any | null): Any | null;
|
|
48
|
+
/**
|
|
49
|
+
* Find a cookie that has been set.
|
|
50
|
+
*
|
|
51
|
+
* @param {String} name Name of the cookie to find
|
|
52
|
+
* @return {Boolean} Whether or not the cookie is set
|
|
53
|
+
*/
|
|
54
|
+
declare function has(name: string): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Returns help link when cookies are enabled or null.
|
|
57
|
+
*
|
|
58
|
+
* @return {(String|null)}
|
|
59
|
+
*/
|
|
60
|
+
declare function getHelpLink(): (string | null);
|
|
61
|
+
/**
|
|
62
|
+
* Sets the value of a cookie and when it will expire.
|
|
63
|
+
*
|
|
64
|
+
* @param {String} name The name of the cookie.
|
|
65
|
+
* @param {String} value The value of the cookie.
|
|
66
|
+
* @param {Number} [expiredays] The number of days until the cookie expires.
|
|
67
|
+
*/
|
|
68
|
+
declare function set(name: string, value: string, expiredays?: number | undefined): void;
|
|
@@ -1,42 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const BrowserDetect_1 = __importDefault(require("./BrowserDetect"));
|
|
3
7
|
const CONST = {
|
|
4
8
|
/**
|
|
5
9
|
* Cookie storing the the name of the page we visited the last time
|
|
6
10
|
*/
|
|
7
11
|
NAME_LAST_PAGE: 'lastPage',
|
|
8
|
-
|
|
9
12
|
/**
|
|
10
13
|
* Cookie storing the name of the reports page we visited the last time (e.g. reports, inbox)
|
|
11
14
|
*/
|
|
12
15
|
NAME_LAST_REPORTS_PAGE: 'lastReportsPage',
|
|
13
|
-
|
|
14
16
|
/**
|
|
15
17
|
* Cookie storing a user's restricted-access support token
|
|
16
18
|
*/
|
|
17
19
|
NAME_STASHED_SUPPORT: '_stashedSupportLogin',
|
|
18
|
-
|
|
19
20
|
/**
|
|
20
21
|
* Cookie set by expensify web that's used to identify a request as coming from web.
|
|
21
22
|
*/
|
|
22
23
|
NAME_WEB_COOKIE: 'expensifyWeb',
|
|
23
|
-
|
|
24
24
|
/**
|
|
25
25
|
* Cookie storing the mode the user wants to use when viewing the expenses page.
|
|
26
26
|
*/
|
|
27
27
|
NAME_EXPENSES_VIEW_MODE: 'expensesPageViewMode',
|
|
28
|
-
|
|
29
28
|
/**
|
|
30
29
|
* Cookie set that denotes a mobile request
|
|
31
30
|
*/
|
|
32
31
|
MOBILE_APP_VERSION: 'appversion',
|
|
33
|
-
|
|
34
32
|
/**
|
|
35
33
|
* Two-Factor Auth device token
|
|
36
34
|
*/
|
|
37
35
|
TWO_FACTOR_DEVICE_TOKEN: 'stashedTwoFactorLogin',
|
|
38
36
|
};
|
|
39
|
-
|
|
40
37
|
/**
|
|
41
38
|
* Deletes a cookie.
|
|
42
39
|
*
|
|
@@ -46,7 +43,6 @@ function remove(name) {
|
|
|
46
43
|
const date = new Date();
|
|
47
44
|
document.cookie = `${name}=; expires=${date.toUTCString()}`;
|
|
48
45
|
}
|
|
49
|
-
|
|
50
46
|
/**
|
|
51
47
|
* Sets the value of a cookie and when it will expire.
|
|
52
48
|
*
|
|
@@ -58,10 +54,8 @@ function set(name, value, expiredays) {
|
|
|
58
54
|
// Get expiry date, set
|
|
59
55
|
const exdate = new Date();
|
|
60
56
|
exdate.setDate(exdate.getDate() + expiredays);
|
|
61
|
-
document.cookie = `${name}=${encodeURIComponent(value)}`
|
|
62
|
-
+ `${((expiredays === null) ? '' : `;expires=${exdate.toUTCString()}`)}`;
|
|
57
|
+
document.cookie = `${name}=${encodeURIComponent(value)}${expiredays === null ? '' : `;expires=${exdate.toUTCString()}`}`;
|
|
63
58
|
}
|
|
64
|
-
|
|
65
59
|
/**
|
|
66
60
|
* Detects if cookies are currently enabled in the browser
|
|
67
61
|
* by trying to create a cookie, see if it exists, and delete it afterwards again.
|
|
@@ -79,7 +73,6 @@ function enabled() {
|
|
|
79
73
|
}
|
|
80
74
|
return result;
|
|
81
75
|
}
|
|
82
|
-
|
|
83
76
|
/**
|
|
84
77
|
* Fetches the value of a cookie.
|
|
85
78
|
*
|
|
@@ -87,7 +80,7 @@ function enabled() {
|
|
|
87
80
|
* @return {String|null} The value of the cookie.
|
|
88
81
|
*/
|
|
89
82
|
function get(name) {
|
|
90
|
-
if (!name ||
|
|
83
|
+
if (!name || document.cookie.length <= 0) {
|
|
91
84
|
return null;
|
|
92
85
|
}
|
|
93
86
|
let start;
|
|
@@ -103,8 +96,6 @@ function get(name) {
|
|
|
103
96
|
}
|
|
104
97
|
return null;
|
|
105
98
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
99
|
/**
|
|
109
100
|
* Parses a cookie value to JSON.
|
|
110
101
|
* Returns a default value specified by param or null.
|
|
@@ -116,16 +107,14 @@ function get(name) {
|
|
|
116
107
|
*/
|
|
117
108
|
function getJSON(name, defaultValue = null) {
|
|
118
109
|
let data;
|
|
119
|
-
|
|
120
110
|
try {
|
|
121
111
|
data = JSON.parse(get(name));
|
|
122
|
-
}
|
|
112
|
+
}
|
|
113
|
+
catch (err) {
|
|
123
114
|
data = defaultValue;
|
|
124
115
|
}
|
|
125
|
-
|
|
126
116
|
return data;
|
|
127
117
|
}
|
|
128
|
-
|
|
129
118
|
/**
|
|
130
119
|
* Find a cookie that has been set.
|
|
131
120
|
*
|
|
@@ -135,7 +124,6 @@ function getJSON(name, defaultValue = null) {
|
|
|
135
124
|
function has(name) {
|
|
136
125
|
return get(name) !== null;
|
|
137
126
|
}
|
|
138
|
-
|
|
139
127
|
/**
|
|
140
128
|
* Returns help link when cookies are enabled or null.
|
|
141
129
|
*
|
|
@@ -145,33 +133,32 @@ function getHelpLink() {
|
|
|
145
133
|
if (enabled()) {
|
|
146
134
|
return null;
|
|
147
135
|
}
|
|
148
|
-
|
|
149
136
|
let helpLink = 'http://www.google.com/search?q=enable+cookies';
|
|
150
|
-
|
|
151
137
|
// Set up help link according to browser
|
|
152
|
-
if (
|
|
138
|
+
if (BrowserDetect_1.default.browser === BrowserDetect_1.default.BROWSERS.EXPLORER) {
|
|
153
139
|
helpLink = 'https://support.microsoft.com/en-us/help/17442/windows-internet-explorer-delete-manage-cookies';
|
|
154
|
-
}
|
|
140
|
+
}
|
|
141
|
+
else if (BrowserDetect_1.default.browser === BrowserDetect_1.default.BROWSERS.SAFARI) {
|
|
155
142
|
helpLink = 'https://support.apple.com/guide/safari/manage-cookies-and-website-data-sfri11471/mac';
|
|
156
|
-
}
|
|
143
|
+
}
|
|
144
|
+
else if (BrowserDetect_1.default.browser === BrowserDetect_1.default.BROWSERS.MOZILLA) {
|
|
157
145
|
helpLink = 'http://support.mozilla.com/en-US/kb/Enabling%20and%20disabling%20cookies';
|
|
158
|
-
}
|
|
146
|
+
}
|
|
147
|
+
else if (BrowserDetect_1.default.browser === BrowserDetect_1.default.BROWSERS.OPERA) {
|
|
159
148
|
helpLink = 'http://www.opera.com/help/tutorials/security/privacy/';
|
|
160
|
-
}
|
|
149
|
+
}
|
|
150
|
+
else if (BrowserDetect_1.default.browser === BrowserDetect_1.default.BROWSERS.CHROME) {
|
|
161
151
|
helpLink = 'http://www.google.com/support/chrome/bin/answer.py?answer=95647';
|
|
162
|
-
}
|
|
152
|
+
}
|
|
153
|
+
else if (BrowserDetect_1.default.browser === BrowserDetect_1.default.BROWSERS.EDGE) {
|
|
163
154
|
helpLink = 'https://privacy.microsoft.com/en-us/windows-10-microsoft-edge-and-privacy';
|
|
164
155
|
}
|
|
165
156
|
return helpLink;
|
|
166
157
|
}
|
|
167
|
-
|
|
168
|
-
export default {
|
|
169
|
-
enabled,
|
|
158
|
+
exports.default = Object.assign({ enabled,
|
|
170
159
|
remove,
|
|
171
160
|
get,
|
|
172
161
|
getJSON,
|
|
173
162
|
has,
|
|
174
163
|
getHelpLink,
|
|
175
|
-
set,
|
|
176
|
-
...CONST
|
|
177
|
-
};
|
|
164
|
+
set }, CONST);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export default CredentialWrapper;
|
|
2
|
+
declare namespace CredentialWrapper {
|
|
3
|
+
/**
|
|
4
|
+
* @returns {Promise} Promise resolves to an object containing partnerUserID and partnerUserSecret
|
|
5
|
+
*/
|
|
6
|
+
function getCredentials(): Promise<any>;
|
|
7
|
+
/**
|
|
8
|
+
* @returns {Object} Object contains randomly generated partnerUserID and partnerUserSecret
|
|
9
|
+
*/
|
|
10
|
+
function generateCredentials(): Object;
|
|
11
|
+
/**
|
|
12
|
+
* @param {Object} credentials
|
|
13
|
+
* @param {String} credentials.partnerUserID
|
|
14
|
+
* @param {String} credentials.partnerUserSecret
|
|
15
|
+
*
|
|
16
|
+
* @returns {Promise} Promise resolves to an object containing partnerUserID and partnerUserSecret
|
|
17
|
+
*/
|
|
18
|
+
function setCredentials(credentials: {
|
|
19
|
+
partnerUserID: string;
|
|
20
|
+
partnerUserSecret: string;
|
|
21
|
+
}): Promise<any>;
|
|
22
|
+
/**
|
|
23
|
+
* @returns {Promise}
|
|
24
|
+
*/
|
|
25
|
+
function clearCredentials(): Promise<any>;
|
|
26
|
+
}
|
|
27
|
+
export namespace LOGIN_PARTNER_DETAILS {
|
|
28
|
+
let CREDENTIALS_KEY: string;
|
|
29
|
+
let EXPENSIFY_PARTNER_PREFIX: string;
|
|
30
|
+
let PARTNER_NAME: string;
|
|
31
|
+
let PARTNER_PASSWORD: string;
|
|
32
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.LOGIN_PARTNER_DETAILS = void 0;
|
|
7
|
+
const localforage_1 = __importDefault(require("localforage"));
|
|
8
|
+
const LOGIN_PARTNER_DETAILS = {
|
|
9
|
+
CREDENTIALS_KEY: 'DEVICE_SESSION_CREDENTIALS',
|
|
10
|
+
EXPENSIFY_PARTNER_PREFIX: 'expensify.',
|
|
11
|
+
PARTNER_NAME: 'chat-expensify-com',
|
|
12
|
+
PARTNER_PASSWORD: 'e21965746fd75f82bb66',
|
|
13
|
+
};
|
|
14
|
+
exports.LOGIN_PARTNER_DETAILS = LOGIN_PARTNER_DETAILS;
|
|
15
|
+
const CredentialWrapper = {
|
|
16
|
+
/**
|
|
17
|
+
* @returns {Promise} Promise resolves to an object containing partnerUserID and partnerUserSecret
|
|
18
|
+
*/
|
|
19
|
+
getCredentials() {
|
|
20
|
+
return localforage_1.default.getItem(LOGIN_PARTNER_DETAILS.CREDENTIALS_KEY);
|
|
21
|
+
},
|
|
22
|
+
/**
|
|
23
|
+
* @returns {Object} Object contains randomly generated partnerUserID and partnerUserSecret
|
|
24
|
+
*/
|
|
25
|
+
generateCredentials() {
|
|
26
|
+
return {
|
|
27
|
+
partnerUserID: LOGIN_PARTNER_DETAILS.EXPENSIFY_PARTNER_PREFIX + crypto.randomUUID(),
|
|
28
|
+
partnerUserSecret: crypto.randomUUID(),
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
/**
|
|
32
|
+
* @param {Object} credentials
|
|
33
|
+
* @param {String} credentials.partnerUserID
|
|
34
|
+
* @param {String} credentials.partnerUserSecret
|
|
35
|
+
*
|
|
36
|
+
* @returns {Promise} Promise resolves to an object containing partnerUserID and partnerUserSecret
|
|
37
|
+
*/
|
|
38
|
+
setCredentials(credentials) {
|
|
39
|
+
if (!credentials.partnerUserID || !credentials.partnerUserSecret) {
|
|
40
|
+
// eslint-disable-next-line prefer-promise-reject-errors
|
|
41
|
+
return Promise.reject('Invalid credential pair');
|
|
42
|
+
}
|
|
43
|
+
return localforage_1.default.setItem(LOGIN_PARTNER_DETAILS.CREDENTIALS_KEY, credentials);
|
|
44
|
+
},
|
|
45
|
+
/**
|
|
46
|
+
* @returns {Promise}
|
|
47
|
+
*/
|
|
48
|
+
clearCredentials() {
|
|
49
|
+
return localforage_1.default.removeItem(LOGIN_PARTNER_DETAILS.CREDENTIALS_KEY);
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
exports.default = CredentialWrapper;
|
package/dist/Device.d.ts
ADDED
package/dist/Device.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getOSAndName = void 0;
|
|
4
|
+
const ua_parser_js_1 = require("ua-parser-js");
|
|
5
|
+
function getOSAndName() {
|
|
6
|
+
const parser = new ua_parser_js_1.UAParser();
|
|
7
|
+
const result = parser.getResult();
|
|
8
|
+
return {
|
|
9
|
+
os: result.os.name,
|
|
10
|
+
osVersion: result.os.version,
|
|
11
|
+
deviceName: result.browser.name,
|
|
12
|
+
deviceVersion: result.browser.version,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
exports.getOSAndName = getOSAndName;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export default class ExpenseRule {
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new instance of this class.
|
|
4
|
+
*
|
|
5
|
+
* @param {Array} ruleArray
|
|
6
|
+
*/
|
|
7
|
+
constructor(ruleArray: any[]);
|
|
8
|
+
/**
|
|
9
|
+
* Returns the applyWhen array associated with the passed field
|
|
10
|
+
* i.e. field == category returns [field: 'category', condition: 'matches', value: 'car']
|
|
11
|
+
*
|
|
12
|
+
* @param {string} field
|
|
13
|
+
*
|
|
14
|
+
* @return {Object}
|
|
15
|
+
*/
|
|
16
|
+
getApplyWhenByField(field: string): Object;
|
|
17
|
+
/**
|
|
18
|
+
* Get the externalID saved deep in the tax field
|
|
19
|
+
*
|
|
20
|
+
* @returns {String}
|
|
21
|
+
*/
|
|
22
|
+
getExternalTaxID(): string;
|
|
23
|
+
/**
|
|
24
|
+
* Checks if the passed expense matches this expense rule
|
|
25
|
+
*
|
|
26
|
+
* @param {SExpense3} expense
|
|
27
|
+
* @returns {boolean}
|
|
28
|
+
*/
|
|
29
|
+
isMatch(expense: SExpense3): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Checks the passed value against the actual based on what the condition (matches, greater, less than, etc.)
|
|
32
|
+
*
|
|
33
|
+
* @param {string} condition
|
|
34
|
+
* @param {Mixed} ruleValue
|
|
35
|
+
* @param {Mixed} transactionValue
|
|
36
|
+
* @returns {boolean}
|
|
37
|
+
*/
|
|
38
|
+
checkCondition(condition: string, ruleValue: Mixed, transactionValue: Mixed): boolean;
|
|
39
|
+
}
|
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const underscore_1 = __importDefault(require("underscore"));
|
|
7
|
+
class ExpenseRule {
|
|
4
8
|
/**
|
|
5
9
|
* Creates a new instance of this class.
|
|
6
10
|
*
|
|
7
11
|
* @param {Array} ruleArray
|
|
8
12
|
*/
|
|
9
13
|
constructor(ruleArray) {
|
|
10
|
-
|
|
14
|
+
underscore_1.default.each(ruleArray, (value, key) => {
|
|
11
15
|
this[key] = value;
|
|
12
16
|
});
|
|
13
17
|
}
|
|
14
|
-
|
|
15
18
|
/**
|
|
16
19
|
* Returns the applyWhen array associated with the passed field
|
|
17
20
|
* i.e. field == category returns [field: 'category', condition: 'matches', value: 'car']
|
|
@@ -21,11 +24,8 @@ export default class ExpenseRule {
|
|
|
21
24
|
* @return {Object}
|
|
22
25
|
*/
|
|
23
26
|
getApplyWhenByField(field) {
|
|
24
|
-
return
|
|
25
|
-
return conditions.field === field;
|
|
26
|
-
}) || {};
|
|
27
|
+
return underscore_1.default.find(this.applyWhen, (conditions) => conditions.field === field) || {};
|
|
27
28
|
}
|
|
28
|
-
|
|
29
29
|
/**
|
|
30
30
|
* Get the externalID saved deep in the tax field
|
|
31
31
|
*
|
|
@@ -34,7 +34,6 @@ export default class ExpenseRule {
|
|
|
34
34
|
getExternalTaxID() {
|
|
35
35
|
return this.tax.field_id_TAX.externalID || '';
|
|
36
36
|
}
|
|
37
|
-
|
|
38
37
|
/**
|
|
39
38
|
* Checks if the passed expense matches this expense rule
|
|
40
39
|
*
|
|
@@ -43,7 +42,7 @@ export default class ExpenseRule {
|
|
|
43
42
|
*/
|
|
44
43
|
isMatch(expense) {
|
|
45
44
|
let isMatch = true;
|
|
46
|
-
|
|
45
|
+
underscore_1.default.each(this.applyWhen, (conditions) => {
|
|
47
46
|
switch (conditions.field) {
|
|
48
47
|
case 'category':
|
|
49
48
|
if (!this.checkCondition(conditions.condition, conditions.value, expense.getCategory())) {
|
|
@@ -54,10 +53,8 @@ export default class ExpenseRule {
|
|
|
54
53
|
break;
|
|
55
54
|
}
|
|
56
55
|
});
|
|
57
|
-
|
|
58
56
|
return isMatch;
|
|
59
57
|
}
|
|
60
|
-
|
|
61
58
|
/**
|
|
62
59
|
* Checks the passed value against the actual based on what the condition (matches, greater, less than, etc.)
|
|
63
60
|
*
|
|
@@ -75,4 +72,5 @@ export default class ExpenseRule {
|
|
|
75
72
|
return false;
|
|
76
73
|
}
|
|
77
74
|
}
|
|
78
|
-
}
|
|
75
|
+
}
|
|
76
|
+
exports.default = ExpenseRule;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
declare type Replacement = (...args: string[], extras?: ExtrasObject) => string;
|
|
2
|
+
declare type Name =
|
|
3
|
+
| 'codeFence'
|
|
4
|
+
| 'inlineCodeBlock'
|
|
5
|
+
| 'email'
|
|
6
|
+
| 'link'
|
|
7
|
+
| 'hereMentions'
|
|
8
|
+
| 'userMentions'
|
|
9
|
+
| 'reportMentions'
|
|
10
|
+
| 'autoEmail'
|
|
11
|
+
| 'autolink'
|
|
12
|
+
| 'quote'
|
|
13
|
+
| 'italic'
|
|
14
|
+
| 'bold'
|
|
15
|
+
| 'strikethrough'
|
|
16
|
+
| 'heading1'
|
|
17
|
+
| 'newline'
|
|
18
|
+
| 'replacepre'
|
|
19
|
+
| 'listItem'
|
|
20
|
+
| 'exclude'
|
|
21
|
+
| 'anchor'
|
|
22
|
+
| 'breakline'
|
|
23
|
+
| 'blockquoteWrapHeadingOpen'
|
|
24
|
+
| 'blockquoteWrapHeadingClose'
|
|
25
|
+
| 'blockElementOpen'
|
|
26
|
+
| 'blockElementClose'
|
|
27
|
+
| 'stripTag';
|
|
28
|
+
declare type Rule = {
|
|
29
|
+
name: Name;
|
|
30
|
+
process?: (textToProcess: string, replacement: Replacement) => string;
|
|
31
|
+
regex?: RegExp;
|
|
32
|
+
replacement: Replacement | string;
|
|
33
|
+
pre?: (input: string) => string;
|
|
34
|
+
post?: (input: string) => string;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
declare type ExtrasObject = {
|
|
38
|
+
reportIdToName?: Record<string, string>;
|
|
39
|
+
accountIDToName?: Record<string, string>;
|
|
40
|
+
};
|
|
41
|
+
export default class ExpensiMark {
|
|
42
|
+
rules: Rule[];
|
|
43
|
+
htmlToMarkdownRules: Rule[];
|
|
44
|
+
htmlToTextRules: Rule[];
|
|
45
|
+
constructor();
|
|
46
|
+
/**
|
|
47
|
+
* Replaces markdown with html elements
|
|
48
|
+
*
|
|
49
|
+
* @param text - Text to parse as markdown
|
|
50
|
+
* @param options - Options to customize the markdown parser
|
|
51
|
+
* @param options.filterRules=[] - An array of name of rules as defined in this class.
|
|
52
|
+
* If not provided, all available rules will be applied. If provided, only the rules in the array will be applied.
|
|
53
|
+
* @param options.disabledRules=[] - An array of name of rules as defined in this class.
|
|
54
|
+
* If not provided, all available rules will be applied. If provided, the rules in the array will be skipped.
|
|
55
|
+
* @param options.shouldEscapeText=true - Whether or not the text should be escaped
|
|
56
|
+
* @param options.shouldKeepRawInput=false - Whether or not the raw input should be kept and returned
|
|
57
|
+
*/
|
|
58
|
+
replace(
|
|
59
|
+
text: string,
|
|
60
|
+
{
|
|
61
|
+
filterRules,
|
|
62
|
+
shouldEscapeText,
|
|
63
|
+
shouldKeepRawInput,
|
|
64
|
+
}?: {
|
|
65
|
+
filterRules?: Name[];
|
|
66
|
+
disabledRules?: Name[];
|
|
67
|
+
shouldEscapeText?: boolean;
|
|
68
|
+
shouldKeepRawInput?: boolean;
|
|
69
|
+
},
|
|
70
|
+
): string;
|
|
71
|
+
/**
|
|
72
|
+
* Checks matched URLs for validity and replace valid links with html elements
|
|
73
|
+
*
|
|
74
|
+
* @param regex
|
|
75
|
+
* @param textToCheck
|
|
76
|
+
* @param replacement
|
|
77
|
+
*/
|
|
78
|
+
modifyTextForUrlLinks(regex: RegExp, textToCheck: string, replacement: Replacement): string;
|
|
79
|
+
/**
|
|
80
|
+
* Checks matched Emails for validity and replace valid links with html elements
|
|
81
|
+
*
|
|
82
|
+
* @param regex
|
|
83
|
+
* @param textToCheck
|
|
84
|
+
* @param replacement
|
|
85
|
+
*/
|
|
86
|
+
modifyTextForEmailLinks(regex: RegExp, textToCheck: string, replacement: Replacement): string;
|
|
87
|
+
/**
|
|
88
|
+
* replace block element with '\n' if :
|
|
89
|
+
* 1. We have text within the element.
|
|
90
|
+
* 2. The text does not end with a new line.
|
|
91
|
+
* 3. The text does not have quote mark '>' .
|
|
92
|
+
* 4. It's not the last element in the string.
|
|
93
|
+
*
|
|
94
|
+
* @param htmlString
|
|
95
|
+
*/
|
|
96
|
+
replaceBlockElementWithNewLine(htmlString: string): string;
|
|
97
|
+
/**
|
|
98
|
+
* Replaces HTML with markdown
|
|
99
|
+
*
|
|
100
|
+
* @param htmlString
|
|
101
|
+
* @param extras
|
|
102
|
+
*/
|
|
103
|
+
htmlToMarkdown(htmlString: string, extras?: ExtrasObject): string;
|
|
104
|
+
/**
|
|
105
|
+
* Convert HTML to text
|
|
106
|
+
*
|
|
107
|
+
* @param htmlString
|
|
108
|
+
* @param extras
|
|
109
|
+
*/
|
|
110
|
+
htmlToText(htmlString: string, extras?: ExtrasObject): string;
|
|
111
|
+
/**
|
|
112
|
+
* Modify text for Quotes replacing chevrons with html elements
|
|
113
|
+
*
|
|
114
|
+
* @param regex
|
|
115
|
+
* @param textToCheck
|
|
116
|
+
* @param replacement
|
|
117
|
+
*/
|
|
118
|
+
modifyTextForQuote(regex: RegExp, textToCheck: string, replacement: Replacement): string;
|
|
119
|
+
/**
|
|
120
|
+
* Format the content of blockquote if the text matches the regex or else just return the original text
|
|
121
|
+
*
|
|
122
|
+
* @param regex
|
|
123
|
+
* @param textToCheck
|
|
124
|
+
* @param replacement
|
|
125
|
+
*/
|
|
126
|
+
formatTextForQuote(regex: RegExp, textToCheck: string, replacement: Replacement): string;
|
|
127
|
+
/**
|
|
128
|
+
* Check if the input text includes only the open or the close tag of an element.
|
|
129
|
+
*
|
|
130
|
+
* @param textToCheck - Text to check
|
|
131
|
+
*/
|
|
132
|
+
containsNonPairTag(textToCheck: string): boolean;
|
|
133
|
+
extractLinksInMarkdownComment(comment: string): string[] | undefined;
|
|
134
|
+
/**
|
|
135
|
+
* Compares two markdown comments and returns a list of the links removed in a new comment.
|
|
136
|
+
*
|
|
137
|
+
* @param oldComment
|
|
138
|
+
* @param newComment
|
|
139
|
+
*/
|
|
140
|
+
getRemovedMarkdownLinks(oldComment: string, newComment: string): string[];
|
|
141
|
+
}
|
|
142
|
+
export {};
|