expensify-common 2.0.187 → 2.0.189
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/CLI.d.ts +160 -0
- package/dist/CLI.js +282 -0
- package/dist/esm/API.d.ts +11 -0
- package/dist/esm/API.js +786 -0
- package/dist/esm/APIDeferred.d.ts +7 -0
- package/dist/esm/APIDeferred.js +216 -0
- package/dist/esm/BrowserDetect.d.ts +19 -0
- package/dist/esm/BrowserDetect.js +105 -0
- package/dist/esm/CLI.d.ts +160 -0
- package/dist/esm/CLI.js +244 -0
- package/dist/esm/CONST.d.ts +1727 -0
- package/dist/esm/CONST.js +1847 -0
- package/dist/esm/Cookie.d.ts +68 -0
- package/dist/esm/Cookie.js +159 -0
- package/dist/esm/CredentialsWrapper.d.ts +32 -0
- package/dist/esm/CredentialsWrapper.js +46 -0
- package/dist/esm/Device.d.ts +8 -0
- package/dist/esm/Device.js +24 -0
- package/dist/esm/ExpenseRule.d.ts +39 -0
- package/dist/esm/ExpenseRule.js +77 -0
- package/dist/esm/ExpensiMark.d.ts +197 -0
- package/dist/esm/ExpensiMark.js +1374 -0
- package/dist/esm/Func.d.ts +40 -0
- package/dist/esm/Func.js +69 -0
- package/dist/esm/Log.d.ts +3 -0
- package/dist/esm/Log.js +35 -0
- package/dist/esm/Logger.d.ts +82 -0
- package/dist/esm/Logger.js +138 -0
- package/dist/esm/Network.d.ts +6 -0
- package/dist/esm/Network.js +168 -0
- package/dist/esm/Num.d.ts +95 -0
- package/dist/esm/Num.js +190 -0
- package/dist/esm/PageEvent.d.ts +25 -0
- package/dist/esm/PageEvent.js +22 -0
- package/dist/esm/PubSub.d.ts +2 -0
- package/dist/esm/PubSub.js +111 -0
- package/dist/esm/ReportHistoryStore.d.ts +8 -0
- package/dist/esm/ReportHistoryStore.js +199 -0
- package/dist/esm/SafeString.d.ts +8 -0
- package/{lib/SafeString.ts → dist/esm/SafeString.js} +8 -13
- package/dist/esm/Templates.d.ts +58 -0
- package/dist/esm/Templates.js +196 -0
- package/dist/esm/Url.d.ts +10 -0
- package/dist/esm/Url.js +15 -0
- package/dist/esm/components/CopyText.d.ts +45 -0
- package/dist/esm/components/CopyText.js +56 -0
- package/dist/esm/components/StepProgressBar.d.ts +26 -0
- package/dist/esm/components/StepProgressBar.js +40 -0
- package/dist/esm/components/form/element/combobox.d.ts +231 -0
- package/dist/esm/components/form/element/combobox.js +812 -0
- package/dist/esm/components/form/element/dropdown.d.ts +35 -0
- package/dist/esm/components/form/element/dropdown.js +61 -0
- package/dist/esm/components/form/element/dropdownItem.d.ts +55 -0
- package/dist/esm/components/form/element/dropdownItem.js +113 -0
- package/dist/esm/components/form/element/onOffSwitch.d.ts +94 -0
- package/dist/esm/components/form/element/onOffSwitch.js +167 -0
- package/dist/esm/components/form/element/switch.d.ts +58 -0
- package/dist/esm/components/form/element/switch.js +98 -0
- package/dist/esm/fastMerge.d.ts +9 -0
- package/dist/esm/fastMerge.js +58 -0
- package/dist/esm/index.d.ts +22 -0
- package/dist/esm/index.js +22 -0
- package/dist/esm/jquery.expensifyIframify.d.ts +9 -0
- package/dist/esm/jquery.expensifyIframify.js +397 -0
- package/dist/esm/md5.d.ts +2 -0
- package/dist/esm/md5.js +170 -0
- package/dist/esm/mixins/PubSub.d.ts +20 -0
- package/dist/esm/mixins/PubSub.js +47 -0
- package/dist/esm/mixins/extraClasses.d.ts +8 -0
- package/dist/esm/mixins/extraClasses.js +37 -0
- package/dist/esm/mixins/validationClasses.d.ts +12 -0
- package/dist/esm/mixins/validationClasses.js +30 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/str.d.ts +604 -0
- package/dist/esm/str.js +1036 -0
- package/dist/esm/tlds.d.ts +2 -0
- package/dist/esm/tlds.js +2 -0
- package/dist/esm/utils.d.ts +30 -0
- package/dist/esm/utils.js +65 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +8 -1
- package/package.json +228 -8
- package/lib/CLI.ts +0 -409
package/dist/esm/CLI.js
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* This file contains a CLI utility class which can be used to declaratively implement a strongly-typed CLI.
|
|
12
|
+
* You provide a CLIConfig defining your arguments, then the class will handle parsing argv, type validation, error handling, and help messages.
|
|
13
|
+
*/
|
|
14
|
+
import * as readline from 'readline';
|
|
15
|
+
import SafeString from './SafeString.js';
|
|
16
|
+
class CLI {
|
|
17
|
+
constructor(config) {
|
|
18
|
+
var _a, _b, _c, _d, _e, _f;
|
|
19
|
+
this.config = config;
|
|
20
|
+
const rawArgs = process.argv.slice(2);
|
|
21
|
+
// Initialize all flags to false by default (including built-in flags)
|
|
22
|
+
this.flags = Object.assign(Object.assign({}, Object.fromEntries(Object.keys((_a = config.flags) !== null && _a !== void 0 ? _a : {}).map((key) => [key, false]))), { yes: false, no: false, help: false });
|
|
23
|
+
try {
|
|
24
|
+
const parsedNamedArgs = {};
|
|
25
|
+
const parsedPositionalArgs = {};
|
|
26
|
+
const providedNamedArgs = new Set();
|
|
27
|
+
let positionalIndex = 0;
|
|
28
|
+
for (let i = 0; i < rawArgs.length; i++) {
|
|
29
|
+
const rawArg = rawArgs.at(i);
|
|
30
|
+
if (rawArg === undefined) {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (rawArg.startsWith('--')) {
|
|
34
|
+
// Either a flag or a named param
|
|
35
|
+
const [rawArgName, rawArgValue] = rawArg.slice(2).split('=');
|
|
36
|
+
if (rawArgName in this.flags) {
|
|
37
|
+
// Arg is a flag
|
|
38
|
+
this.flags[rawArgName] = true;
|
|
39
|
+
}
|
|
40
|
+
else if (config.namedArgs && rawArgName in config.namedArgs) {
|
|
41
|
+
// Arg is a named arg
|
|
42
|
+
providedNamedArgs.add(rawArgName);
|
|
43
|
+
// Grab the value from the split token, otherwise go for the next token
|
|
44
|
+
let argValueBeforeParse = '';
|
|
45
|
+
if (rawArgValue) {
|
|
46
|
+
argValueBeforeParse = rawArgValue;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
argValueBeforeParse = (_b = rawArgs.at(++i)) !== null && _b !== void 0 ? _b : '';
|
|
50
|
+
if (!argValueBeforeParse || argValueBeforeParse.startsWith('--')) {
|
|
51
|
+
throw new Error(`Missing value for --${rawArgName}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const spec = config.namedArgs[rawArgName];
|
|
55
|
+
parsedNamedArgs[rawArgName] = CLI.parseStringArg(argValueBeforeParse, rawArgName, spec);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
console.error(`Unknown flag: --${rawArgName}`);
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
// Arg is a positional arg
|
|
64
|
+
const spec = (_c = config.positionalArgs) === null || _c === void 0 ? void 0 : _c.at(positionalIndex);
|
|
65
|
+
if (spec === undefined) {
|
|
66
|
+
throw new Error(`Unexpected arg: ${rawArg}`);
|
|
67
|
+
}
|
|
68
|
+
if (spec.variadic) {
|
|
69
|
+
// Variadic: collect this and all remaining non-flag args into an array
|
|
70
|
+
const collected = [];
|
|
71
|
+
for (let j = i; j < rawArgs.length; j++) {
|
|
72
|
+
const remaining = rawArgs.at(j);
|
|
73
|
+
if (remaining === undefined || remaining.startsWith('--')) {
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
collected.push(remaining);
|
|
77
|
+
}
|
|
78
|
+
parsedPositionalArgs[spec.name] = collected;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
parsedPositionalArgs[spec.name] = CLI.parseStringArg(rawArg, spec.name, spec);
|
|
82
|
+
positionalIndex++;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// Handle help command
|
|
86
|
+
if (this.flags.help) {
|
|
87
|
+
this.printHelp();
|
|
88
|
+
process.exit(0);
|
|
89
|
+
}
|
|
90
|
+
// Handle supersession logic
|
|
91
|
+
const supersededArgs = new Set();
|
|
92
|
+
for (const [name, spec] of Object.entries((_d = config.namedArgs) !== null && _d !== void 0 ? _d : {})) {
|
|
93
|
+
if (providedNamedArgs.has(name) && spec.supersedes) {
|
|
94
|
+
for (const supersededArg of spec.supersedes) {
|
|
95
|
+
supersededArgs.add(supersededArg);
|
|
96
|
+
if (providedNamedArgs.has(supersededArg)) {
|
|
97
|
+
console.warn(`⚠️ Warning: --${supersededArg} is superseded by --${name} and will be ignored.`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// Validate that all required args are present, assign defaults where values are not parsed
|
|
103
|
+
for (const [name, spec] of Object.entries((_e = config.namedArgs) !== null && _e !== void 0 ? _e : {})) {
|
|
104
|
+
if (name in parsedNamedArgs) {
|
|
105
|
+
if (supersededArgs.has(name)) {
|
|
106
|
+
parsedNamedArgs[name] = undefined;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else if (supersededArgs.has(name)) {
|
|
110
|
+
// This arg was superseded, so don't require it and don't assign a default
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
else if (spec.default !== undefined) {
|
|
114
|
+
parsedNamedArgs[name] = spec.default;
|
|
115
|
+
}
|
|
116
|
+
else if (spec.required === false) {
|
|
117
|
+
// Explicitly marked as optional, leave undefined
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
// Arguments without defaults are required by default (unless explicitly marked as optional)
|
|
122
|
+
throw new Error(`Missing required named argument --${name}`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
for (const spec of (_f = config.positionalArgs) !== null && _f !== void 0 ? _f : []) {
|
|
126
|
+
if (!(spec.name in parsedPositionalArgs)) {
|
|
127
|
+
if (spec.default !== undefined) {
|
|
128
|
+
parsedPositionalArgs[spec.name] = spec.default;
|
|
129
|
+
}
|
|
130
|
+
else if (spec.variadic) {
|
|
131
|
+
parsedPositionalArgs[spec.name] = [];
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
throw new Error(`Missing required positional argument --${spec.name}`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
this.namedArgs = parsedNamedArgs;
|
|
139
|
+
this.positionalArgs = parsedPositionalArgs;
|
|
140
|
+
}
|
|
141
|
+
catch (err) {
|
|
142
|
+
// If help flag was set, the error is from process.exit(0) in tests (where it's mocked to throw) - just rethrow it
|
|
143
|
+
if (this.flags.help) {
|
|
144
|
+
throw err;
|
|
145
|
+
}
|
|
146
|
+
if (err instanceof Error) {
|
|
147
|
+
console.error(err.message);
|
|
148
|
+
this.printHelp();
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
console.error('An unexpected error occurred initializing the CLI.');
|
|
152
|
+
}
|
|
153
|
+
process.exit(1);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
printHelp() {
|
|
157
|
+
var _a;
|
|
158
|
+
const { flags = {}, namedArgs = {}, positionalArgs = [] } = this.config;
|
|
159
|
+
const scriptName = (_a = process.argv.at(1)) !== null && _a !== void 0 ? _a : 'script.ts';
|
|
160
|
+
const positionalUsage = positionalArgs
|
|
161
|
+
.map((arg) => {
|
|
162
|
+
const label = arg.variadic ? `${arg.name}...` : arg.name;
|
|
163
|
+
return arg.default === undefined ? `<${label}>` : `[${label}]`;
|
|
164
|
+
})
|
|
165
|
+
.join(' ');
|
|
166
|
+
const namedArgUsage = Object.keys(namedArgs)
|
|
167
|
+
.map((key) => `[--${key} <value>]`)
|
|
168
|
+
.join(' ');
|
|
169
|
+
const flagUsage = [...Object.keys(flags), '--yes', '--no', '--help'].map((key) => `[${key.startsWith('--') ? key : `--${key}`}]`).join(' ');
|
|
170
|
+
console.log(`\nUsage: npx ts-node ${scriptName} ${flagUsage} ${namedArgUsage} ${positionalUsage}\n`);
|
|
171
|
+
console.log('Flags:');
|
|
172
|
+
for (const [name, spec] of Object.entries(flags)) {
|
|
173
|
+
console.log(` --${name.padEnd(20)} ${spec.description}`);
|
|
174
|
+
}
|
|
175
|
+
// Built-in flags
|
|
176
|
+
console.log(` --${'yes'.padEnd(20)} Automatically answer "yes" to all confirmation prompts.`);
|
|
177
|
+
console.log(` --${'no'.padEnd(20)} Automatically answer "no" to all confirmation prompts.`);
|
|
178
|
+
console.log(` --${'help'.padEnd(20)} Show this help message.`);
|
|
179
|
+
console.log('');
|
|
180
|
+
if (Object.keys(namedArgs).length > 0) {
|
|
181
|
+
console.log('Named Arguments:');
|
|
182
|
+
for (const [name, spec] of Object.entries(namedArgs)) {
|
|
183
|
+
const defaultLabel = spec.default !== undefined ? ` (default: ${SafeString(spec.default)})` : '';
|
|
184
|
+
const supersededLabel = spec.supersedes && spec.supersedes.length > 0 ? ` (supersedes: ${spec.supersedes.join(', ')})` : '';
|
|
185
|
+
console.log(` --${name.padEnd(20)} ${spec.description}${defaultLabel}${supersededLabel}`);
|
|
186
|
+
}
|
|
187
|
+
console.log('');
|
|
188
|
+
}
|
|
189
|
+
if (positionalArgs.length > 0) {
|
|
190
|
+
console.log('Positional Arguments:');
|
|
191
|
+
for (const arg of positionalArgs) {
|
|
192
|
+
const defaultLabel = arg.default !== undefined ? ` (default: ${SafeString(arg.default)})` : '';
|
|
193
|
+
console.log(` ${arg.name.padEnd(22)} ${arg.description}${defaultLabel}`);
|
|
194
|
+
}
|
|
195
|
+
console.log('');
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
static parseStringArg(rawString, paramName, spec) {
|
|
199
|
+
if ('parse' in spec && !!spec.parse) {
|
|
200
|
+
try {
|
|
201
|
+
return spec.parse(rawString);
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
let errorMessage = '';
|
|
205
|
+
if (error instanceof Error) {
|
|
206
|
+
errorMessage = error.message;
|
|
207
|
+
}
|
|
208
|
+
console.error(`Invalid value for --${paramName}: ${errorMessage}`);
|
|
209
|
+
process.exit(1);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
return rawString;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Prompts the user for confirmation and returns true if they confirm (y/yes), false otherwise.
|
|
218
|
+
* If --yes flag was passed, returns true immediately without prompting.
|
|
219
|
+
* If --no flag was passed, returns false immediately without prompting.
|
|
220
|
+
*/
|
|
221
|
+
promptUserConfirmation(message) {
|
|
222
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
223
|
+
// Check for built-in flags first
|
|
224
|
+
if (this.flags.yes) {
|
|
225
|
+
return true;
|
|
226
|
+
}
|
|
227
|
+
if (this.flags.no) {
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
const rl = readline.createInterface({
|
|
231
|
+
input: process.stdin,
|
|
232
|
+
output: process.stdout,
|
|
233
|
+
});
|
|
234
|
+
return new Promise((resolve) => {
|
|
235
|
+
rl.question(message, (answer) => {
|
|
236
|
+
rl.close();
|
|
237
|
+
const normalizedAnswer = answer.trim().toLowerCase();
|
|
238
|
+
resolve(normalizedAnswer === 'y' || normalizedAnswer === 'yes');
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
export default CLI;
|