brex-cli 0.0.0-canary.107cbde → 0.0.0-canary.38c7d2f
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 +7 -5
- package/dist/main.js +93 -418
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
# brex-cli
|
|
2
2
|
|
|
3
|
+

|
|
4
|
+
|
|
3
5
|
[](https://opensource.org/licenses/MIT)
|
|
4
6
|
|
|
5
7
|
A powerful CLI for the [Brex Platform API](https://developer.brex.com/). Manage accounts, transactions, transfers, recipients, webhooks, and more from your terminal.
|
|
6
8
|
|
|
7
9
|
## Features
|
|
8
10
|
|
|
9
|
-
- **Full Brex API coverage** — accounts, transactions, transfers, recipients, cards, statements, webhooks, and more
|
|
10
|
-
- **Multiple output formats** — human-readable tables or JSON for scripting
|
|
11
|
-
- **Secure token storage** — credentials stored safely in `~/.brex/`
|
|
12
|
-
- **Cash & card accounts** — unified interface for both account types
|
|
13
|
-
- **Scriptable** — no interactive prompts, perfect for CI/CD and automation
|
|
11
|
+
- 🏦 **Full Brex API coverage** — accounts, transactions, transfers, recipients, cards, statements, webhooks, and more
|
|
12
|
+
- 📊 **Multiple output formats** — human-readable tables or JSON for scripting
|
|
13
|
+
- 🔐 **Secure token storage** — credentials stored safely in `~/.brex/`
|
|
14
|
+
- 💳 **Cash & card accounts** — unified interface for both account types
|
|
15
|
+
- 🤖 **Scriptable** — no interactive prompts, perfect for CI/CD and automation
|
|
14
16
|
|
|
15
17
|
## Installation
|
|
16
18
|
|
package/dist/main.js
CHANGED
|
@@ -2,334 +2,9 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// sources/config.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var homedir = function() {
|
|
9
|
-
return "/";
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
// node:path
|
|
13
|
-
function assertPath(path) {
|
|
14
|
-
if (typeof path !== "string")
|
|
15
|
-
throw TypeError("Path must be a string. Received " + JSON.stringify(path));
|
|
16
|
-
}
|
|
17
|
-
function normalizeStringPosix(path, allowAboveRoot) {
|
|
18
|
-
var res = "", lastSegmentLength = 0, lastSlash = -1, dots = 0, code;
|
|
19
|
-
for (var i = 0;i <= path.length; ++i) {
|
|
20
|
-
if (i < path.length)
|
|
21
|
-
code = path.charCodeAt(i);
|
|
22
|
-
else if (code === 47)
|
|
23
|
-
break;
|
|
24
|
-
else
|
|
25
|
-
code = 47;
|
|
26
|
-
if (code === 47) {
|
|
27
|
-
if (lastSlash === i - 1 || dots === 1)
|
|
28
|
-
;
|
|
29
|
-
else if (lastSlash !== i - 1 && dots === 2) {
|
|
30
|
-
if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 || res.charCodeAt(res.length - 2) !== 46) {
|
|
31
|
-
if (res.length > 2) {
|
|
32
|
-
var lastSlashIndex = res.lastIndexOf("/");
|
|
33
|
-
if (lastSlashIndex !== res.length - 1) {
|
|
34
|
-
if (lastSlashIndex === -1)
|
|
35
|
-
res = "", lastSegmentLength = 0;
|
|
36
|
-
else
|
|
37
|
-
res = res.slice(0, lastSlashIndex), lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
38
|
-
lastSlash = i, dots = 0;
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
} else if (res.length === 2 || res.length === 1) {
|
|
42
|
-
res = "", lastSegmentLength = 0, lastSlash = i, dots = 0;
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
if (allowAboveRoot) {
|
|
47
|
-
if (res.length > 0)
|
|
48
|
-
res += "/..";
|
|
49
|
-
else
|
|
50
|
-
res = "..";
|
|
51
|
-
lastSegmentLength = 2;
|
|
52
|
-
}
|
|
53
|
-
} else {
|
|
54
|
-
if (res.length > 0)
|
|
55
|
-
res += "/" + path.slice(lastSlash + 1, i);
|
|
56
|
-
else
|
|
57
|
-
res = path.slice(lastSlash + 1, i);
|
|
58
|
-
lastSegmentLength = i - lastSlash - 1;
|
|
59
|
-
}
|
|
60
|
-
lastSlash = i, dots = 0;
|
|
61
|
-
} else if (code === 46 && dots !== -1)
|
|
62
|
-
++dots;
|
|
63
|
-
else
|
|
64
|
-
dots = -1;
|
|
65
|
-
}
|
|
66
|
-
return res;
|
|
67
|
-
}
|
|
68
|
-
function _format(sep, pathObject) {
|
|
69
|
-
var dir = pathObject.dir || pathObject.root, base = pathObject.base || (pathObject.name || "") + (pathObject.ext || "");
|
|
70
|
-
if (!dir)
|
|
71
|
-
return base;
|
|
72
|
-
if (dir === pathObject.root)
|
|
73
|
-
return dir + base;
|
|
74
|
-
return dir + sep + base;
|
|
75
|
-
}
|
|
76
|
-
function resolve() {
|
|
77
|
-
var resolvedPath = "", resolvedAbsolute = false, cwd;
|
|
78
|
-
for (var i = arguments.length - 1;i >= -1 && !resolvedAbsolute; i--) {
|
|
79
|
-
var path;
|
|
80
|
-
if (i >= 0)
|
|
81
|
-
path = arguments[i];
|
|
82
|
-
else {
|
|
83
|
-
if (cwd === undefined)
|
|
84
|
-
cwd = process.cwd();
|
|
85
|
-
path = cwd;
|
|
86
|
-
}
|
|
87
|
-
if (assertPath(path), path.length === 0)
|
|
88
|
-
continue;
|
|
89
|
-
resolvedPath = path + "/" + resolvedPath, resolvedAbsolute = path.charCodeAt(0) === 47;
|
|
90
|
-
}
|
|
91
|
-
if (resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute), resolvedAbsolute)
|
|
92
|
-
if (resolvedPath.length > 0)
|
|
93
|
-
return "/" + resolvedPath;
|
|
94
|
-
else
|
|
95
|
-
return "/";
|
|
96
|
-
else if (resolvedPath.length > 0)
|
|
97
|
-
return resolvedPath;
|
|
98
|
-
else
|
|
99
|
-
return ".";
|
|
100
|
-
}
|
|
101
|
-
function normalize(path) {
|
|
102
|
-
if (assertPath(path), path.length === 0)
|
|
103
|
-
return ".";
|
|
104
|
-
var isAbsolute = path.charCodeAt(0) === 47, trailingSeparator = path.charCodeAt(path.length - 1) === 47;
|
|
105
|
-
if (path = normalizeStringPosix(path, !isAbsolute), path.length === 0 && !isAbsolute)
|
|
106
|
-
path = ".";
|
|
107
|
-
if (path.length > 0 && trailingSeparator)
|
|
108
|
-
path += "/";
|
|
109
|
-
if (isAbsolute)
|
|
110
|
-
return "/" + path;
|
|
111
|
-
return path;
|
|
112
|
-
}
|
|
113
|
-
function isAbsolute(path) {
|
|
114
|
-
return assertPath(path), path.length > 0 && path.charCodeAt(0) === 47;
|
|
115
|
-
}
|
|
116
|
-
function join() {
|
|
117
|
-
if (arguments.length === 0)
|
|
118
|
-
return ".";
|
|
119
|
-
var joined;
|
|
120
|
-
for (var i = 0;i < arguments.length; ++i) {
|
|
121
|
-
var arg = arguments[i];
|
|
122
|
-
if (assertPath(arg), arg.length > 0)
|
|
123
|
-
if (joined === undefined)
|
|
124
|
-
joined = arg;
|
|
125
|
-
else
|
|
126
|
-
joined += "/" + arg;
|
|
127
|
-
}
|
|
128
|
-
if (joined === undefined)
|
|
129
|
-
return ".";
|
|
130
|
-
return normalize(joined);
|
|
131
|
-
}
|
|
132
|
-
function relative(from, to) {
|
|
133
|
-
if (assertPath(from), assertPath(to), from === to)
|
|
134
|
-
return "";
|
|
135
|
-
if (from = resolve(from), to = resolve(to), from === to)
|
|
136
|
-
return "";
|
|
137
|
-
var fromStart = 1;
|
|
138
|
-
for (;fromStart < from.length; ++fromStart)
|
|
139
|
-
if (from.charCodeAt(fromStart) !== 47)
|
|
140
|
-
break;
|
|
141
|
-
var fromEnd = from.length, fromLen = fromEnd - fromStart, toStart = 1;
|
|
142
|
-
for (;toStart < to.length; ++toStart)
|
|
143
|
-
if (to.charCodeAt(toStart) !== 47)
|
|
144
|
-
break;
|
|
145
|
-
var toEnd = to.length, toLen = toEnd - toStart, length = fromLen < toLen ? fromLen : toLen, lastCommonSep = -1, i = 0;
|
|
146
|
-
for (;i <= length; ++i) {
|
|
147
|
-
if (i === length) {
|
|
148
|
-
if (toLen > length) {
|
|
149
|
-
if (to.charCodeAt(toStart + i) === 47)
|
|
150
|
-
return to.slice(toStart + i + 1);
|
|
151
|
-
else if (i === 0)
|
|
152
|
-
return to.slice(toStart + i);
|
|
153
|
-
} else if (fromLen > length) {
|
|
154
|
-
if (from.charCodeAt(fromStart + i) === 47)
|
|
155
|
-
lastCommonSep = i;
|
|
156
|
-
else if (i === 0)
|
|
157
|
-
lastCommonSep = 0;
|
|
158
|
-
}
|
|
159
|
-
break;
|
|
160
|
-
}
|
|
161
|
-
var fromCode = from.charCodeAt(fromStart + i), toCode = to.charCodeAt(toStart + i);
|
|
162
|
-
if (fromCode !== toCode)
|
|
163
|
-
break;
|
|
164
|
-
else if (fromCode === 47)
|
|
165
|
-
lastCommonSep = i;
|
|
166
|
-
}
|
|
167
|
-
var out = "";
|
|
168
|
-
for (i = fromStart + lastCommonSep + 1;i <= fromEnd; ++i)
|
|
169
|
-
if (i === fromEnd || from.charCodeAt(i) === 47)
|
|
170
|
-
if (out.length === 0)
|
|
171
|
-
out += "..";
|
|
172
|
-
else
|
|
173
|
-
out += "/..";
|
|
174
|
-
if (out.length > 0)
|
|
175
|
-
return out + to.slice(toStart + lastCommonSep);
|
|
176
|
-
else {
|
|
177
|
-
if (toStart += lastCommonSep, to.charCodeAt(toStart) === 47)
|
|
178
|
-
++toStart;
|
|
179
|
-
return to.slice(toStart);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
function _makeLong(path) {
|
|
183
|
-
return path;
|
|
184
|
-
}
|
|
185
|
-
function dirname(path) {
|
|
186
|
-
if (assertPath(path), path.length === 0)
|
|
187
|
-
return ".";
|
|
188
|
-
var code = path.charCodeAt(0), hasRoot = code === 47, end = -1, matchedSlash = true;
|
|
189
|
-
for (var i = path.length - 1;i >= 1; --i)
|
|
190
|
-
if (code = path.charCodeAt(i), code === 47) {
|
|
191
|
-
if (!matchedSlash) {
|
|
192
|
-
end = i;
|
|
193
|
-
break;
|
|
194
|
-
}
|
|
195
|
-
} else
|
|
196
|
-
matchedSlash = false;
|
|
197
|
-
if (end === -1)
|
|
198
|
-
return hasRoot ? "/" : ".";
|
|
199
|
-
if (hasRoot && end === 1)
|
|
200
|
-
return "//";
|
|
201
|
-
return path.slice(0, end);
|
|
202
|
-
}
|
|
203
|
-
function basename(path, ext) {
|
|
204
|
-
if (ext !== undefined && typeof ext !== "string")
|
|
205
|
-
throw TypeError('"ext" argument must be a string');
|
|
206
|
-
assertPath(path);
|
|
207
|
-
var start = 0, end = -1, matchedSlash = true, i;
|
|
208
|
-
if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
|
|
209
|
-
if (ext.length === path.length && ext === path)
|
|
210
|
-
return "";
|
|
211
|
-
var extIdx = ext.length - 1, firstNonSlashEnd = -1;
|
|
212
|
-
for (i = path.length - 1;i >= 0; --i) {
|
|
213
|
-
var code = path.charCodeAt(i);
|
|
214
|
-
if (code === 47) {
|
|
215
|
-
if (!matchedSlash) {
|
|
216
|
-
start = i + 1;
|
|
217
|
-
break;
|
|
218
|
-
}
|
|
219
|
-
} else {
|
|
220
|
-
if (firstNonSlashEnd === -1)
|
|
221
|
-
matchedSlash = false, firstNonSlashEnd = i + 1;
|
|
222
|
-
if (extIdx >= 0)
|
|
223
|
-
if (code === ext.charCodeAt(extIdx)) {
|
|
224
|
-
if (--extIdx === -1)
|
|
225
|
-
end = i;
|
|
226
|
-
} else
|
|
227
|
-
extIdx = -1, end = firstNonSlashEnd;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
if (start === end)
|
|
231
|
-
end = firstNonSlashEnd;
|
|
232
|
-
else if (end === -1)
|
|
233
|
-
end = path.length;
|
|
234
|
-
return path.slice(start, end);
|
|
235
|
-
} else {
|
|
236
|
-
for (i = path.length - 1;i >= 0; --i)
|
|
237
|
-
if (path.charCodeAt(i) === 47) {
|
|
238
|
-
if (!matchedSlash) {
|
|
239
|
-
start = i + 1;
|
|
240
|
-
break;
|
|
241
|
-
}
|
|
242
|
-
} else if (end === -1)
|
|
243
|
-
matchedSlash = false, end = i + 1;
|
|
244
|
-
if (end === -1)
|
|
245
|
-
return "";
|
|
246
|
-
return path.slice(start, end);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
function extname(path) {
|
|
250
|
-
assertPath(path);
|
|
251
|
-
var startDot = -1, startPart = 0, end = -1, matchedSlash = true, preDotState = 0;
|
|
252
|
-
for (var i = path.length - 1;i >= 0; --i) {
|
|
253
|
-
var code = path.charCodeAt(i);
|
|
254
|
-
if (code === 47) {
|
|
255
|
-
if (!matchedSlash) {
|
|
256
|
-
startPart = i + 1;
|
|
257
|
-
break;
|
|
258
|
-
}
|
|
259
|
-
continue;
|
|
260
|
-
}
|
|
261
|
-
if (end === -1)
|
|
262
|
-
matchedSlash = false, end = i + 1;
|
|
263
|
-
if (code === 46) {
|
|
264
|
-
if (startDot === -1)
|
|
265
|
-
startDot = i;
|
|
266
|
-
else if (preDotState !== 1)
|
|
267
|
-
preDotState = 1;
|
|
268
|
-
} else if (startDot !== -1)
|
|
269
|
-
preDotState = -1;
|
|
270
|
-
}
|
|
271
|
-
if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)
|
|
272
|
-
return "";
|
|
273
|
-
return path.slice(startDot, end);
|
|
274
|
-
}
|
|
275
|
-
function format(pathObject) {
|
|
276
|
-
if (pathObject === null || typeof pathObject !== "object")
|
|
277
|
-
throw TypeError('The "pathObject" argument must be of type Object. Received type ' + typeof pathObject);
|
|
278
|
-
return _format("/", pathObject);
|
|
279
|
-
}
|
|
280
|
-
function parse(path) {
|
|
281
|
-
assertPath(path);
|
|
282
|
-
var ret = { root: "", dir: "", base: "", ext: "", name: "" };
|
|
283
|
-
if (path.length === 0)
|
|
284
|
-
return ret;
|
|
285
|
-
var code = path.charCodeAt(0), isAbsolute2 = code === 47, start;
|
|
286
|
-
if (isAbsolute2)
|
|
287
|
-
ret.root = "/", start = 1;
|
|
288
|
-
else
|
|
289
|
-
start = 0;
|
|
290
|
-
var startDot = -1, startPart = 0, end = -1, matchedSlash = true, i = path.length - 1, preDotState = 0;
|
|
291
|
-
for (;i >= start; --i) {
|
|
292
|
-
if (code = path.charCodeAt(i), code === 47) {
|
|
293
|
-
if (!matchedSlash) {
|
|
294
|
-
startPart = i + 1;
|
|
295
|
-
break;
|
|
296
|
-
}
|
|
297
|
-
continue;
|
|
298
|
-
}
|
|
299
|
-
if (end === -1)
|
|
300
|
-
matchedSlash = false, end = i + 1;
|
|
301
|
-
if (code === 46) {
|
|
302
|
-
if (startDot === -1)
|
|
303
|
-
startDot = i;
|
|
304
|
-
else if (preDotState !== 1)
|
|
305
|
-
preDotState = 1;
|
|
306
|
-
} else if (startDot !== -1)
|
|
307
|
-
preDotState = -1;
|
|
308
|
-
}
|
|
309
|
-
if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
|
|
310
|
-
if (end !== -1)
|
|
311
|
-
if (startPart === 0 && isAbsolute2)
|
|
312
|
-
ret.base = ret.name = path.slice(1, end);
|
|
313
|
-
else
|
|
314
|
-
ret.base = ret.name = path.slice(startPart, end);
|
|
315
|
-
} else {
|
|
316
|
-
if (startPart === 0 && isAbsolute2)
|
|
317
|
-
ret.name = path.slice(1, startDot), ret.base = path.slice(1, end);
|
|
318
|
-
else
|
|
319
|
-
ret.name = path.slice(startPart, startDot), ret.base = path.slice(startPart, end);
|
|
320
|
-
ret.ext = path.slice(startDot, end);
|
|
321
|
-
}
|
|
322
|
-
if (startPart > 0)
|
|
323
|
-
ret.dir = path.slice(0, startPart - 1);
|
|
324
|
-
else if (isAbsolute2)
|
|
325
|
-
ret.dir = "/";
|
|
326
|
-
return ret;
|
|
327
|
-
}
|
|
328
|
-
var sep = "/";
|
|
329
|
-
var delimiter = ":";
|
|
330
|
-
var posix = ((p) => (p.posix = p, p))({ resolve, normalize, isAbsolute, join, relative, _makeLong, dirname, basename, extname, format, parse, sep, delimiter, win32: null, posix: null });
|
|
331
|
-
|
|
332
|
-
// sources/config.ts
|
|
5
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync, unlinkSync } from "node:fs";
|
|
6
|
+
import { homedir } from "node:os";
|
|
7
|
+
import { join } from "node:path";
|
|
333
8
|
var CONFIG_DIR = join(homedir(), ".brex");
|
|
334
9
|
var TOKEN_PATH = join(CONFIG_DIR, "token");
|
|
335
10
|
var CONFIG_PATH = join(CONFIG_DIR, "config.json");
|
|
@@ -552,16 +227,16 @@ class BrexApiError2 extends Error {
|
|
|
552
227
|
|
|
553
228
|
// sources/output.ts
|
|
554
229
|
function parseOutputFlag(args) {
|
|
555
|
-
let
|
|
230
|
+
let format = "table";
|
|
556
231
|
const remaining = [];
|
|
557
232
|
for (const arg of args) {
|
|
558
233
|
if (arg === "--json") {
|
|
559
|
-
|
|
234
|
+
format = "json";
|
|
560
235
|
continue;
|
|
561
236
|
}
|
|
562
237
|
remaining.push(arg);
|
|
563
238
|
}
|
|
564
|
-
return { format
|
|
239
|
+
return { format, args: remaining };
|
|
565
240
|
}
|
|
566
241
|
function printJson(data) {
|
|
567
242
|
console.log(JSON.stringify(data, null, 2));
|
|
@@ -641,18 +316,18 @@ var accountsCommand = {
|
|
|
641
316
|
usage: USAGE4,
|
|
642
317
|
aliases: ["account", "acc"],
|
|
643
318
|
run: async (args, context) => {
|
|
644
|
-
const { format
|
|
319
|
+
const { format, args: remaining } = parseOutputFlag(args);
|
|
645
320
|
const subcommand = remaining[0] ?? "list";
|
|
646
321
|
switch (subcommand) {
|
|
647
322
|
case "list":
|
|
648
|
-
await listAccounts(context, parseListOptions(remaining.slice(1)),
|
|
323
|
+
await listAccounts(context, parseListOptions(remaining.slice(1)), format);
|
|
649
324
|
return;
|
|
650
325
|
case "get": {
|
|
651
326
|
const accountId = remaining[1];
|
|
652
327
|
if (!accountId) {
|
|
653
328
|
throw new Error("Missing account ID. Usage: brex accounts get <account-id> [--type cash|card]");
|
|
654
329
|
}
|
|
655
|
-
await getAccount(context, accountId, parseGetOptions(remaining.slice(2)),
|
|
330
|
+
await getAccount(context, accountId, parseGetOptions(remaining.slice(2)), format);
|
|
656
331
|
return;
|
|
657
332
|
}
|
|
658
333
|
default:
|
|
@@ -711,13 +386,13 @@ function parseGetOptions(args) {
|
|
|
711
386
|
}
|
|
712
387
|
return { type };
|
|
713
388
|
}
|
|
714
|
-
async function listAccounts(context, options,
|
|
389
|
+
async function listAccounts(context, options, format) {
|
|
715
390
|
const cashPath = withCursor("/v2/accounts/cash", options.cursor);
|
|
716
391
|
const cardPath = withCursor("/v2/accounts/card", options.cursor);
|
|
717
392
|
if (options.type === "cash") {
|
|
718
393
|
const cashResponse2 = await context.client.fetch(cashPath);
|
|
719
394
|
const cashAccounts2 = extractItems(cashResponse2, ["items", "cash_accounts", "accounts"]);
|
|
720
|
-
if (
|
|
395
|
+
if (format === "json") {
|
|
721
396
|
printJson({ items: cashAccounts2, nextCursor: cashResponse2.next_cursor ?? null });
|
|
722
397
|
return;
|
|
723
398
|
}
|
|
@@ -731,7 +406,7 @@ Next cursor: ${cashResponse2.next_cursor}`);
|
|
|
731
406
|
if (options.type === "card") {
|
|
732
407
|
const cardResponse2 = await context.client.fetch(cardPath);
|
|
733
408
|
const cardAccounts2 = extractItems(cardResponse2, ["items", "card_accounts", "accounts"]);
|
|
734
|
-
if (
|
|
409
|
+
if (format === "json") {
|
|
735
410
|
printJson({ items: cardAccounts2, nextCursor: cardResponse2.next_cursor ?? null });
|
|
736
411
|
return;
|
|
737
412
|
}
|
|
@@ -748,7 +423,7 @@ Next cursor: ${cardResponse2.next_cursor}`);
|
|
|
748
423
|
]);
|
|
749
424
|
const cashAccounts = extractItems(cashResponse, ["items", "cash_accounts", "accounts"]);
|
|
750
425
|
const cardAccounts = extractItems(cardResponse, ["items", "card_accounts", "accounts"]);
|
|
751
|
-
if (
|
|
426
|
+
if (format === "json") {
|
|
752
427
|
printJson({
|
|
753
428
|
cash: { items: cashAccounts, nextCursor: cashResponse.next_cursor ?? null },
|
|
754
429
|
card: { items: cardAccounts, nextCursor: cardResponse.next_cursor ?? null }
|
|
@@ -761,22 +436,22 @@ Next cursor: ${cardResponse2.next_cursor}`);
|
|
|
761
436
|
];
|
|
762
437
|
printAccountsTable(rows);
|
|
763
438
|
}
|
|
764
|
-
async function getAccount(context, accountId, options,
|
|
439
|
+
async function getAccount(context, accountId, options, format) {
|
|
765
440
|
const fetchCash = async () => context.client.fetch(`/v2/accounts/cash/${accountId}`);
|
|
766
441
|
const fetchCard = async () => context.client.fetch(`/v2/accounts/card/${accountId}`);
|
|
767
442
|
if (options.type === "cash") {
|
|
768
443
|
const account = await fetchCash();
|
|
769
|
-
renderAccount(account, "cash",
|
|
444
|
+
renderAccount(account, "cash", format);
|
|
770
445
|
return;
|
|
771
446
|
}
|
|
772
447
|
if (options.type === "card") {
|
|
773
448
|
const account = await fetchCard();
|
|
774
|
-
renderAccount(account, "card",
|
|
449
|
+
renderAccount(account, "card", format);
|
|
775
450
|
return;
|
|
776
451
|
}
|
|
777
452
|
try {
|
|
778
453
|
const account = await fetchCash();
|
|
779
|
-
renderAccount(account, "cash",
|
|
454
|
+
renderAccount(account, "cash", format);
|
|
780
455
|
return;
|
|
781
456
|
} catch (error) {
|
|
782
457
|
if (!(error instanceof BrexApiError2) || error.status !== 404) {
|
|
@@ -784,10 +459,10 @@ async function getAccount(context, accountId, options, format2) {
|
|
|
784
459
|
}
|
|
785
460
|
}
|
|
786
461
|
const cardAccount = await fetchCard();
|
|
787
|
-
renderAccount(cardAccount, "card",
|
|
462
|
+
renderAccount(cardAccount, "card", format);
|
|
788
463
|
}
|
|
789
|
-
function renderAccount(account, type,
|
|
790
|
-
if (
|
|
464
|
+
function renderAccount(account, type, format) {
|
|
465
|
+
if (format === "json") {
|
|
791
466
|
printJson(account);
|
|
792
467
|
return;
|
|
793
468
|
}
|
|
@@ -866,7 +541,7 @@ var transactionsCommand = {
|
|
|
866
541
|
usage: USAGE5,
|
|
867
542
|
aliases: ["tx", "txn"],
|
|
868
543
|
run: async (args, context) => {
|
|
869
|
-
const { format
|
|
544
|
+
const { format, args: remaining } = parseOutputFlag(args);
|
|
870
545
|
if (remaining.length === 0) {
|
|
871
546
|
throw new Error("Missing account ID. Usage: brex transactions <account-id>");
|
|
872
547
|
}
|
|
@@ -877,7 +552,7 @@ var transactionsCommand = {
|
|
|
877
552
|
if (!accountId2 || !transactionId) {
|
|
878
553
|
throw new Error("Usage: brex transactions get <account-id> <transaction-id> [--type cash|card]");
|
|
879
554
|
}
|
|
880
|
-
await getTransaction(context, accountId2, transactionId, parseGetOptions2(remaining.slice(3)),
|
|
555
|
+
await getTransaction(context, accountId2, transactionId, parseGetOptions2(remaining.slice(3)), format);
|
|
881
556
|
return;
|
|
882
557
|
}
|
|
883
558
|
if (firstArg === "send") {
|
|
@@ -885,7 +560,7 @@ var transactionsCommand = {
|
|
|
885
560
|
}
|
|
886
561
|
const accountId = firstArg;
|
|
887
562
|
const options = parseListOptions2(remaining.slice(1));
|
|
888
|
-
await listTransactions(context, accountId, options,
|
|
563
|
+
await listTransactions(context, accountId, options, format);
|
|
889
564
|
}
|
|
890
565
|
};
|
|
891
566
|
function parseListOptions2(args) {
|
|
@@ -960,12 +635,12 @@ function parseGetOptions2(args) {
|
|
|
960
635
|
}
|
|
961
636
|
return { type };
|
|
962
637
|
}
|
|
963
|
-
async function listTransactions(context, accountId, options,
|
|
638
|
+
async function listTransactions(context, accountId, options, format) {
|
|
964
639
|
const pathBase = options.type === "cash" ? `/v2/transactions/cash/${accountId}` : `/v2/transactions/card/${accountId}`;
|
|
965
640
|
const path = withQuery(pathBase, options);
|
|
966
641
|
const response = await context.client.fetch(path);
|
|
967
642
|
const transactions = response.items ?? response.transactions ?? [];
|
|
968
|
-
if (
|
|
643
|
+
if (format === "json") {
|
|
969
644
|
printJson({ items: transactions, nextCursor: response.next_cursor ?? null });
|
|
970
645
|
return;
|
|
971
646
|
}
|
|
@@ -986,14 +661,14 @@ async function listTransactions(context, accountId, options, format2) {
|
|
|
986
661
|
Next cursor: ${response.next_cursor}`);
|
|
987
662
|
}
|
|
988
663
|
}
|
|
989
|
-
async function getTransaction(context, accountId, transactionId, options,
|
|
664
|
+
async function getTransaction(context, accountId, transactionId, options, format) {
|
|
990
665
|
const path = options.type === "cash" ? `/v2/transactions/cash/${accountId}/${transactionId}` : `/v2/transactions/card/${accountId}/${transactionId}`;
|
|
991
666
|
const response = await context.client.fetch(path);
|
|
992
667
|
const transaction = response.cash_transaction ?? response.card_transaction ?? response.transaction ?? response.item;
|
|
993
668
|
if (!transaction) {
|
|
994
669
|
throw new Error("Brex API returned an empty transaction payload.");
|
|
995
670
|
}
|
|
996
|
-
if (
|
|
671
|
+
if (format === "json") {
|
|
997
672
|
printJson(transaction);
|
|
998
673
|
return;
|
|
999
674
|
}
|
|
@@ -1045,21 +720,21 @@ var transferCommand = {
|
|
|
1045
720
|
description: "Create and inspect transfers.",
|
|
1046
721
|
usage: USAGE6,
|
|
1047
722
|
run: async (args, context) => {
|
|
1048
|
-
const { format
|
|
723
|
+
const { format, args: remaining } = parseOutputFlag(args);
|
|
1049
724
|
const subcommand = remaining[0];
|
|
1050
725
|
if (subcommand === "get") {
|
|
1051
726
|
const transferId = remaining[1];
|
|
1052
727
|
if (!transferId)
|
|
1053
728
|
throw new Error("Usage: brex transfer get <transfer-id>");
|
|
1054
|
-
await getTransfer(context, transferId,
|
|
729
|
+
await getTransfer(context, transferId, format);
|
|
1055
730
|
return;
|
|
1056
731
|
}
|
|
1057
732
|
if (subcommand === "list") {
|
|
1058
|
-
await listTransfers(context, parseListTransferOptions(remaining.slice(1)),
|
|
733
|
+
await listTransfers(context, parseListTransferOptions(remaining.slice(1)), format);
|
|
1059
734
|
return;
|
|
1060
735
|
}
|
|
1061
736
|
const options = parseCreateTransferOptions(remaining);
|
|
1062
|
-
await createTransfer(context, options,
|
|
737
|
+
await createTransfer(context, options, format);
|
|
1063
738
|
}
|
|
1064
739
|
};
|
|
1065
740
|
function parseCreateTransferOptions(args) {
|
|
@@ -1176,7 +851,7 @@ function parseListTransferOptions(args) {
|
|
|
1176
851
|
}
|
|
1177
852
|
return options;
|
|
1178
853
|
}
|
|
1179
|
-
async function createTransfer(context, options,
|
|
854
|
+
async function createTransfer(context, options, format) {
|
|
1180
855
|
const body = {
|
|
1181
856
|
from_account: {
|
|
1182
857
|
cash_account: {
|
|
@@ -1202,22 +877,22 @@ async function createTransfer(context, options, format2) {
|
|
|
1202
877
|
body: JSON.stringify(body)
|
|
1203
878
|
});
|
|
1204
879
|
const transfer = response.transfer ?? response.item ?? response;
|
|
1205
|
-
if (
|
|
880
|
+
if (format === "json") {
|
|
1206
881
|
printJson(transfer);
|
|
1207
882
|
return;
|
|
1208
883
|
}
|
|
1209
884
|
printTransferDetails(transfer, "Transfer Created");
|
|
1210
885
|
}
|
|
1211
|
-
async function getTransfer(context, transferId,
|
|
886
|
+
async function getTransfer(context, transferId, format) {
|
|
1212
887
|
const response = await context.client.fetch(`/v1/transfers/${transferId}`);
|
|
1213
888
|
const transfer = response.transfer ?? response.item ?? response;
|
|
1214
|
-
if (
|
|
889
|
+
if (format === "json") {
|
|
1215
890
|
printJson(transfer);
|
|
1216
891
|
return;
|
|
1217
892
|
}
|
|
1218
893
|
printTransferDetails(transfer, "Transfer Details");
|
|
1219
894
|
}
|
|
1220
|
-
async function listTransfers(context, options,
|
|
895
|
+
async function listTransfers(context, options, format) {
|
|
1221
896
|
const params = new URLSearchParams;
|
|
1222
897
|
if (options.cursor)
|
|
1223
898
|
params.set("cursor", options.cursor);
|
|
@@ -1233,7 +908,7 @@ async function listTransfers(context, options, format2) {
|
|
|
1233
908
|
const path = query ? `/v1/transfers?${query}` : "/v1/transfers";
|
|
1234
909
|
const response = await context.client.fetch(path);
|
|
1235
910
|
const transfers = response.items ?? response.transfers ?? [];
|
|
1236
|
-
if (
|
|
911
|
+
if (format === "json") {
|
|
1237
912
|
printJson({ items: transfers, nextCursor: response.next_cursor ?? null });
|
|
1238
913
|
return;
|
|
1239
914
|
}
|
|
@@ -1285,21 +960,21 @@ var recipientsCommand = {
|
|
|
1285
960
|
usage: USAGE7,
|
|
1286
961
|
aliases: ["recipient", "recip"],
|
|
1287
962
|
run: async (args, context) => {
|
|
1288
|
-
const { format
|
|
963
|
+
const { format, args: remaining } = parseOutputFlag(args);
|
|
1289
964
|
const subcommand = remaining[0] ?? "list";
|
|
1290
965
|
switch (subcommand) {
|
|
1291
966
|
case "list":
|
|
1292
|
-
await listRecipients(context, parseListOptions3(remaining.slice(1)),
|
|
967
|
+
await listRecipients(context, parseListOptions3(remaining.slice(1)), format);
|
|
1293
968
|
return;
|
|
1294
969
|
case "get": {
|
|
1295
970
|
const recipientId = remaining[1];
|
|
1296
971
|
if (!recipientId)
|
|
1297
972
|
throw new Error("Missing recipient ID. Usage: brex recipients get <counterparty-id>");
|
|
1298
|
-
await getRecipient(context, recipientId,
|
|
973
|
+
await getRecipient(context, recipientId, format);
|
|
1299
974
|
return;
|
|
1300
975
|
}
|
|
1301
976
|
case "add":
|
|
1302
|
-
await addRecipient(context, parseAddOptions(remaining.slice(1)),
|
|
977
|
+
await addRecipient(context, parseAddOptions(remaining.slice(1)), format);
|
|
1303
978
|
return;
|
|
1304
979
|
case "delete": {
|
|
1305
980
|
const recipientId = remaining[1];
|
|
@@ -1416,7 +1091,7 @@ function parseAddOptions(args) {
|
|
|
1416
1091
|
throw new Error("Missing required --routing");
|
|
1417
1092
|
return { name, accountNumber, routingNumber, accountType, country, currency };
|
|
1418
1093
|
}
|
|
1419
|
-
async function listRecipients(context, options,
|
|
1094
|
+
async function listRecipients(context, options, format) {
|
|
1420
1095
|
const params = new URLSearchParams;
|
|
1421
1096
|
if (options.limit)
|
|
1422
1097
|
params.set("limit", String(options.limit));
|
|
@@ -1428,7 +1103,7 @@ async function listRecipients(context, options, format2) {
|
|
|
1428
1103
|
const path = query ? `/v1/payment_counterparties?${query}` : "/v1/payment_counterparties";
|
|
1429
1104
|
const response = await context.client.fetch(path);
|
|
1430
1105
|
const recipients = response.items ?? response.payment_counterparties ?? [];
|
|
1431
|
-
if (
|
|
1106
|
+
if (format === "json") {
|
|
1432
1107
|
printJson({ items: recipients, nextCursor: response.next_cursor ?? null });
|
|
1433
1108
|
return;
|
|
1434
1109
|
}
|
|
@@ -1457,10 +1132,10 @@ async function listRecipients(context, options, format2) {
|
|
|
1457
1132
|
Next cursor: ${response.next_cursor}`);
|
|
1458
1133
|
}
|
|
1459
1134
|
}
|
|
1460
|
-
async function getRecipient(context, recipientId,
|
|
1135
|
+
async function getRecipient(context, recipientId, format) {
|
|
1461
1136
|
const response = await context.client.fetch(`/v1/payment_counterparties/${recipientId}`);
|
|
1462
1137
|
const recipient = response.payment_counterparty ?? response.item ?? response;
|
|
1463
|
-
if (
|
|
1138
|
+
if (format === "json") {
|
|
1464
1139
|
printJson(recipient);
|
|
1465
1140
|
return;
|
|
1466
1141
|
}
|
|
@@ -1480,7 +1155,7 @@ async function getRecipient(context, recipientId, format2) {
|
|
|
1480
1155
|
if (bank?.currency)
|
|
1481
1156
|
console.log(`Currency: ${bank.currency}`);
|
|
1482
1157
|
}
|
|
1483
|
-
async function addRecipient(context, options,
|
|
1158
|
+
async function addRecipient(context, options, format) {
|
|
1484
1159
|
const body = {
|
|
1485
1160
|
name: options.name,
|
|
1486
1161
|
payment_instrument: {
|
|
@@ -1498,7 +1173,7 @@ async function addRecipient(context, options, format2) {
|
|
|
1498
1173
|
body: JSON.stringify(body)
|
|
1499
1174
|
});
|
|
1500
1175
|
const recipient = response.payment_counterparty ?? response.item ?? response;
|
|
1501
|
-
if (
|
|
1176
|
+
if (format === "json") {
|
|
1502
1177
|
printJson(recipient);
|
|
1503
1178
|
return;
|
|
1504
1179
|
}
|
|
@@ -1524,22 +1199,22 @@ var cardsCommand = {
|
|
|
1524
1199
|
usage: USAGE8,
|
|
1525
1200
|
aliases: ["card"],
|
|
1526
1201
|
run: async (args, context) => {
|
|
1527
|
-
const { format
|
|
1202
|
+
const { format, args: remaining } = parseOutputFlag(args);
|
|
1528
1203
|
const subcommand = remaining[0] ?? "list";
|
|
1529
1204
|
if (subcommand === "get") {
|
|
1530
1205
|
const cardId = remaining[1];
|
|
1531
1206
|
if (!cardId) {
|
|
1532
1207
|
throw new Error("Usage: brex cards get <card-id>");
|
|
1533
1208
|
}
|
|
1534
|
-
await getCard(context, cardId,
|
|
1209
|
+
await getCard(context, cardId, format);
|
|
1535
1210
|
return;
|
|
1536
1211
|
}
|
|
1537
1212
|
if (subcommand !== "list" && !subcommand.startsWith("-")) {
|
|
1538
|
-
await getCard(context, subcommand,
|
|
1213
|
+
await getCard(context, subcommand, format);
|
|
1539
1214
|
return;
|
|
1540
1215
|
}
|
|
1541
1216
|
const listArgs = subcommand === "list" ? remaining.slice(1) : remaining;
|
|
1542
|
-
await listCards(context, parseListOptions4(listArgs),
|
|
1217
|
+
await listCards(context, parseListOptions4(listArgs), format);
|
|
1543
1218
|
}
|
|
1544
1219
|
};
|
|
1545
1220
|
function parseListOptions4(args) {
|
|
@@ -1581,7 +1256,7 @@ function parseListOptions4(args) {
|
|
|
1581
1256
|
}
|
|
1582
1257
|
return { userId, cursor, limit };
|
|
1583
1258
|
}
|
|
1584
|
-
async function listCards(context, options,
|
|
1259
|
+
async function listCards(context, options, format) {
|
|
1585
1260
|
const params = new URLSearchParams;
|
|
1586
1261
|
if (options.userId)
|
|
1587
1262
|
params.set("user_id", options.userId);
|
|
@@ -1593,7 +1268,7 @@ async function listCards(context, options, format2) {
|
|
|
1593
1268
|
const path = query ? `/v2/cards?${query}` : "/v2/cards";
|
|
1594
1269
|
const response = await context.client.fetch(path);
|
|
1595
1270
|
const cards = response.items ?? response.cards ?? [];
|
|
1596
|
-
if (
|
|
1271
|
+
if (format === "json") {
|
|
1597
1272
|
printJson({ items: cards, nextCursor: response.next_cursor ?? null });
|
|
1598
1273
|
return;
|
|
1599
1274
|
}
|
|
@@ -1621,10 +1296,10 @@ async function listCards(context, options, format2) {
|
|
|
1621
1296
|
Next cursor: ${response.next_cursor}`);
|
|
1622
1297
|
}
|
|
1623
1298
|
}
|
|
1624
|
-
async function getCard(context, cardId,
|
|
1299
|
+
async function getCard(context, cardId, format) {
|
|
1625
1300
|
const response = await context.client.fetch(`/v2/cards/${cardId}`);
|
|
1626
1301
|
const card = response.card ?? response.item ?? response;
|
|
1627
|
-
if (
|
|
1302
|
+
if (format === "json") {
|
|
1628
1303
|
printJson(card);
|
|
1629
1304
|
return;
|
|
1630
1305
|
}
|
|
@@ -1655,7 +1330,7 @@ var statementsCommand = {
|
|
|
1655
1330
|
usage: USAGE9,
|
|
1656
1331
|
aliases: ["statement"],
|
|
1657
1332
|
run: async (args, context) => {
|
|
1658
|
-
const { format
|
|
1333
|
+
const { format, args: remaining } = parseOutputFlag(args);
|
|
1659
1334
|
const firstArg = remaining[0] ?? "list";
|
|
1660
1335
|
if (firstArg === "get") {
|
|
1661
1336
|
const statementId = remaining[1];
|
|
@@ -1663,11 +1338,11 @@ var statementsCommand = {
|
|
|
1663
1338
|
throw new Error("Usage: brex statements get <statement-id> [--scope primary|additional] [--account-id <id>]");
|
|
1664
1339
|
}
|
|
1665
1340
|
const options2 = parseSharedOptions(remaining.slice(2));
|
|
1666
|
-
await getStatement(context, statementId, options2,
|
|
1341
|
+
await getStatement(context, statementId, options2, format);
|
|
1667
1342
|
return;
|
|
1668
1343
|
}
|
|
1669
1344
|
const options = parseListOptions5(remaining.slice(firstArg === "list" ? 1 : 0));
|
|
1670
|
-
await listStatements(context, options,
|
|
1345
|
+
await listStatements(context, options, format);
|
|
1671
1346
|
}
|
|
1672
1347
|
};
|
|
1673
1348
|
function parseListOptions5(args) {
|
|
@@ -1724,11 +1399,11 @@ function parseSharedOptions(args) {
|
|
|
1724
1399
|
}
|
|
1725
1400
|
return { scope, accountId };
|
|
1726
1401
|
}
|
|
1727
|
-
async function listStatements(context, options,
|
|
1402
|
+
async function listStatements(context, options, format) {
|
|
1728
1403
|
const path = options.scope === "primary" ? withCursor2("/v2/accounts/card/primary/statements", options.cursor) : withCursor2(`/v2/accounts/card/additional/${options.accountId}/statements`, options.cursor);
|
|
1729
1404
|
const response = await context.client.fetch(path);
|
|
1730
1405
|
const statements = response.items ?? response.statements ?? [];
|
|
1731
|
-
if (
|
|
1406
|
+
if (format === "json") {
|
|
1732
1407
|
printJson({ items: statements, nextCursor: response.next_cursor ?? null });
|
|
1733
1408
|
return;
|
|
1734
1409
|
}
|
|
@@ -1756,14 +1431,14 @@ async function listStatements(context, options, format2) {
|
|
|
1756
1431
|
Next cursor: ${response.next_cursor}`);
|
|
1757
1432
|
}
|
|
1758
1433
|
}
|
|
1759
|
-
async function getStatement(context, statementId, options,
|
|
1434
|
+
async function getStatement(context, statementId, options, format) {
|
|
1760
1435
|
const path = options.scope === "primary" ? `/v2/accounts/card/primary/statements/${statementId}` : `/v2/accounts/card/additional/${options.accountId}/statements/${statementId}`;
|
|
1761
1436
|
const response = await context.client.fetch(path);
|
|
1762
1437
|
const statement = response.account_statement ?? response.statement ?? response.item;
|
|
1763
1438
|
if (!statement) {
|
|
1764
1439
|
throw new Error("Brex API returned an empty statement payload.");
|
|
1765
1440
|
}
|
|
1766
|
-
if (
|
|
1441
|
+
if (format === "json") {
|
|
1767
1442
|
printJson(statement);
|
|
1768
1443
|
return;
|
|
1769
1444
|
}
|
|
@@ -1796,27 +1471,27 @@ var webhooksCommand = {
|
|
|
1796
1471
|
usage: USAGE10,
|
|
1797
1472
|
aliases: ["webhook", "wh"],
|
|
1798
1473
|
run: async (args, context) => {
|
|
1799
|
-
const { format
|
|
1474
|
+
const { format, args: remaining } = parseOutputFlag(args);
|
|
1800
1475
|
const subcommand = remaining[0] ?? "list";
|
|
1801
1476
|
switch (subcommand) {
|
|
1802
1477
|
case "list":
|
|
1803
|
-
await listWebhooks(context, parseListOptions6(remaining.slice(1)),
|
|
1478
|
+
await listWebhooks(context, parseListOptions6(remaining.slice(1)), format);
|
|
1804
1479
|
return;
|
|
1805
1480
|
case "get": {
|
|
1806
1481
|
const webhookId = remaining[1];
|
|
1807
1482
|
if (!webhookId)
|
|
1808
1483
|
throw new Error("Missing webhook ID. Usage: brex webhooks get <webhook-id>");
|
|
1809
|
-
await getWebhook(context, webhookId,
|
|
1484
|
+
await getWebhook(context, webhookId, format);
|
|
1810
1485
|
return;
|
|
1811
1486
|
}
|
|
1812
1487
|
case "create":
|
|
1813
|
-
await createWebhook(context, parseCreateOptions(remaining.slice(1)),
|
|
1488
|
+
await createWebhook(context, parseCreateOptions(remaining.slice(1)), format);
|
|
1814
1489
|
return;
|
|
1815
1490
|
case "update": {
|
|
1816
1491
|
const webhookId = remaining[1];
|
|
1817
1492
|
if (!webhookId)
|
|
1818
1493
|
throw new Error("Missing webhook ID. Usage: brex webhooks update <webhook-id> ...");
|
|
1819
|
-
await updateWebhook(context, webhookId, parseUpdateOptions(remaining.slice(2)),
|
|
1494
|
+
await updateWebhook(context, webhookId, parseUpdateOptions(remaining.slice(2)), format);
|
|
1820
1495
|
return;
|
|
1821
1496
|
}
|
|
1822
1497
|
case "delete": {
|
|
@@ -1933,7 +1608,7 @@ function parseUpdateOptions(args) {
|
|
|
1933
1608
|
}
|
|
1934
1609
|
return options;
|
|
1935
1610
|
}
|
|
1936
|
-
async function listWebhooks(context, options,
|
|
1611
|
+
async function listWebhooks(context, options, format) {
|
|
1937
1612
|
const params = new URLSearchParams;
|
|
1938
1613
|
if (options.cursor)
|
|
1939
1614
|
params.set("cursor", options.cursor);
|
|
@@ -1943,7 +1618,7 @@ async function listWebhooks(context, options, format2) {
|
|
|
1943
1618
|
const path = query ? `/v1/webhooks?${query}` : "/v1/webhooks";
|
|
1944
1619
|
const response = await context.client.fetch(path);
|
|
1945
1620
|
const webhooks = response.items ?? response.webhooks ?? [];
|
|
1946
|
-
if (
|
|
1621
|
+
if (format === "json") {
|
|
1947
1622
|
printJson({ items: webhooks, nextCursor: response.next_cursor ?? null });
|
|
1948
1623
|
return;
|
|
1949
1624
|
}
|
|
@@ -1967,10 +1642,10 @@ async function listWebhooks(context, options, format2) {
|
|
|
1967
1642
|
Next cursor: ${response.next_cursor}`);
|
|
1968
1643
|
}
|
|
1969
1644
|
}
|
|
1970
|
-
async function getWebhook(context, webhookId,
|
|
1645
|
+
async function getWebhook(context, webhookId, format) {
|
|
1971
1646
|
const response = await context.client.fetch(`/v1/webhooks/${webhookId}`);
|
|
1972
1647
|
const webhook = response.webhook ?? response.item ?? response;
|
|
1973
|
-
if (
|
|
1648
|
+
if (format === "json") {
|
|
1974
1649
|
printJson(webhook);
|
|
1975
1650
|
return;
|
|
1976
1651
|
}
|
|
@@ -1982,7 +1657,7 @@ async function getWebhook(context, webhookId, format2) {
|
|
|
1982
1657
|
console.log(`Status: ${webhook.status ?? "-"}`);
|
|
1983
1658
|
console.log(`Events: ${events.length > 0 ? events.join(", ") : "-"}`);
|
|
1984
1659
|
}
|
|
1985
|
-
async function createWebhook(context, options,
|
|
1660
|
+
async function createWebhook(context, options, format) {
|
|
1986
1661
|
const body = {
|
|
1987
1662
|
url: options.url
|
|
1988
1663
|
};
|
|
@@ -1999,7 +1674,7 @@ async function createWebhook(context, options, format2) {
|
|
|
1999
1674
|
body: JSON.stringify(body)
|
|
2000
1675
|
});
|
|
2001
1676
|
const webhook = response.webhook ?? response.item ?? response;
|
|
2002
|
-
if (
|
|
1677
|
+
if (format === "json") {
|
|
2003
1678
|
printJson(webhook);
|
|
2004
1679
|
return;
|
|
2005
1680
|
}
|
|
@@ -2009,7 +1684,7 @@ async function createWebhook(context, options, format2) {
|
|
|
2009
1684
|
console.log(`URL: ${webhook.url ?? "-"}`);
|
|
2010
1685
|
console.log(`Status: ${webhook.status ?? "-"}`);
|
|
2011
1686
|
}
|
|
2012
|
-
async function updateWebhook(context, webhookId, options,
|
|
1687
|
+
async function updateWebhook(context, webhookId, options, format) {
|
|
2013
1688
|
const body = {};
|
|
2014
1689
|
if (options.url)
|
|
2015
1690
|
body.url = options.url;
|
|
@@ -2026,7 +1701,7 @@ async function updateWebhook(context, webhookId, options, format2) {
|
|
|
2026
1701
|
body: JSON.stringify(body)
|
|
2027
1702
|
});
|
|
2028
1703
|
const webhook = response.webhook ?? response.item ?? response;
|
|
2029
|
-
if (
|
|
1704
|
+
if (format === "json") {
|
|
2030
1705
|
printJson(webhook);
|
|
2031
1706
|
return;
|
|
2032
1707
|
}
|
|
@@ -2052,21 +1727,21 @@ var eventsCommand = {
|
|
|
2052
1727
|
usage: USAGE11,
|
|
2053
1728
|
aliases: ["event"],
|
|
2054
1729
|
run: async (args, context) => {
|
|
2055
|
-
const { format
|
|
1730
|
+
const { format, args: remaining } = parseOutputFlag(args);
|
|
2056
1731
|
const subcommand = remaining[0] ?? "list";
|
|
2057
1732
|
if (subcommand === "list") {
|
|
2058
|
-
await listEvents(context, parseListOptions7(remaining.slice(1)),
|
|
1733
|
+
await listEvents(context, parseListOptions7(remaining.slice(1)), format);
|
|
2059
1734
|
return;
|
|
2060
1735
|
}
|
|
2061
1736
|
if (subcommand === "get") {
|
|
2062
1737
|
const eventId = remaining[1];
|
|
2063
1738
|
if (!eventId)
|
|
2064
1739
|
throw new Error("Missing event ID. Usage: brex events get <event-id>");
|
|
2065
|
-
await getEvent(context, eventId,
|
|
1740
|
+
await getEvent(context, eventId, format);
|
|
2066
1741
|
return;
|
|
2067
1742
|
}
|
|
2068
1743
|
if (!subcommand.startsWith("-")) {
|
|
2069
|
-
await getEvent(context, subcommand,
|
|
1744
|
+
await getEvent(context, subcommand, format);
|
|
2070
1745
|
return;
|
|
2071
1746
|
}
|
|
2072
1747
|
throw new Error(`Unknown subcommand: ${subcommand}`);
|
|
@@ -2123,7 +1798,7 @@ function parseListOptions7(args) {
|
|
|
2123
1798
|
}
|
|
2124
1799
|
return options;
|
|
2125
1800
|
}
|
|
2126
|
-
async function listEvents(context, options,
|
|
1801
|
+
async function listEvents(context, options, format) {
|
|
2127
1802
|
const params = new URLSearchParams;
|
|
2128
1803
|
if (options.eventType)
|
|
2129
1804
|
params.set("event_type", options.eventType);
|
|
@@ -2139,7 +1814,7 @@ async function listEvents(context, options, format2) {
|
|
|
2139
1814
|
const path = query ? `/v1/events?${query}` : "/v1/events";
|
|
2140
1815
|
const response = await context.client.fetch(path);
|
|
2141
1816
|
const events = response.items ?? response.events ?? [];
|
|
2142
|
-
if (
|
|
1817
|
+
if (format === "json") {
|
|
2143
1818
|
printJson({ items: events, nextCursor: response.next_cursor ?? null });
|
|
2144
1819
|
return;
|
|
2145
1820
|
}
|
|
@@ -2163,10 +1838,10 @@ async function listEvents(context, options, format2) {
|
|
|
2163
1838
|
Next cursor: ${response.next_cursor}`);
|
|
2164
1839
|
}
|
|
2165
1840
|
}
|
|
2166
|
-
async function getEvent(context, eventId,
|
|
1841
|
+
async function getEvent(context, eventId, format) {
|
|
2167
1842
|
const response = await context.client.fetch(`/v1/events/${eventId}`);
|
|
2168
1843
|
const event = response.event ?? response.item ?? response;
|
|
2169
|
-
if (
|
|
1844
|
+
if (format === "json") {
|
|
2170
1845
|
printJson(event);
|
|
2171
1846
|
return;
|
|
2172
1847
|
}
|
|
@@ -2190,10 +1865,10 @@ var organizationCommand = {
|
|
|
2190
1865
|
usage: USAGE12,
|
|
2191
1866
|
aliases: ["org"],
|
|
2192
1867
|
run: async (args, context) => {
|
|
2193
|
-
const { format
|
|
1868
|
+
const { format } = parseOutputFlag(args);
|
|
2194
1869
|
const response = await context.client.fetch("/v2/company");
|
|
2195
1870
|
const company = response.company ?? response.item ?? response;
|
|
2196
|
-
if (
|
|
1871
|
+
if (format === "json") {
|
|
2197
1872
|
printJson(company);
|
|
2198
1873
|
return;
|
|
2199
1874
|
}
|
|
@@ -2234,22 +1909,22 @@ var usersCommand = {
|
|
|
2234
1909
|
usage: USAGE13,
|
|
2235
1910
|
aliases: ["user"],
|
|
2236
1911
|
run: async (args, context) => {
|
|
2237
|
-
const { format
|
|
1912
|
+
const { format, args: remaining } = parseOutputFlag(args);
|
|
2238
1913
|
const subcommand = remaining[0] ?? "list";
|
|
2239
1914
|
switch (subcommand) {
|
|
2240
1915
|
case "list":
|
|
2241
|
-
await listUsers(context, parseListOptions8(remaining.slice(1)),
|
|
1916
|
+
await listUsers(context, parseListOptions8(remaining.slice(1)), format);
|
|
2242
1917
|
return;
|
|
2243
1918
|
case "get": {
|
|
2244
1919
|
const userId = remaining[1];
|
|
2245
1920
|
if (!userId)
|
|
2246
1921
|
throw new Error("Missing user ID. Usage: brex users get <user-id>");
|
|
2247
|
-
await getUser(context, userId,
|
|
1922
|
+
await getUser(context, userId, format);
|
|
2248
1923
|
return;
|
|
2249
1924
|
}
|
|
2250
1925
|
default:
|
|
2251
1926
|
if (!subcommand.startsWith("-")) {
|
|
2252
|
-
await getUser(context, subcommand,
|
|
1927
|
+
await getUser(context, subcommand, format);
|
|
2253
1928
|
return;
|
|
2254
1929
|
}
|
|
2255
1930
|
throw new Error(`Unknown subcommand: ${subcommand}`);
|
|
@@ -2283,7 +1958,7 @@ function parseListOptions8(args) {
|
|
|
2283
1958
|
}
|
|
2284
1959
|
return { cursor, email };
|
|
2285
1960
|
}
|
|
2286
|
-
async function listUsers(context, options,
|
|
1961
|
+
async function listUsers(context, options, format) {
|
|
2287
1962
|
const params = new URLSearchParams;
|
|
2288
1963
|
if (options.cursor)
|
|
2289
1964
|
params.set("cursor", options.cursor);
|
|
@@ -2293,7 +1968,7 @@ async function listUsers(context, options, format2) {
|
|
|
2293
1968
|
const path = query ? `/v2/users?${query}` : "/v2/users";
|
|
2294
1969
|
const response = await context.client.fetch(path);
|
|
2295
1970
|
const users = response.items ?? response.users ?? [];
|
|
2296
|
-
if (
|
|
1971
|
+
if (format === "json") {
|
|
2297
1972
|
printJson({ items: users, nextCursor: response.next_cursor ?? null });
|
|
2298
1973
|
return;
|
|
2299
1974
|
}
|
|
@@ -2321,10 +1996,10 @@ async function listUsers(context, options, format2) {
|
|
|
2321
1996
|
Next cursor: ${response.next_cursor}`);
|
|
2322
1997
|
}
|
|
2323
1998
|
}
|
|
2324
|
-
async function getUser(context, userId,
|
|
1999
|
+
async function getUser(context, userId, format) {
|
|
2325
2000
|
const response = await context.client.fetch(`/v2/users/${userId}`);
|
|
2326
2001
|
const user = response.user ?? response.item ?? response;
|
|
2327
|
-
if (
|
|
2002
|
+
if (format === "json") {
|
|
2328
2003
|
printJson(user);
|
|
2329
2004
|
return;
|
|
2330
2005
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brex-cli",
|
|
3
|
-
"version": "0.0.0-canary.
|
|
3
|
+
"version": "0.0.0-canary.38c7d2f",
|
|
4
4
|
"description": "CLI for Brex Banking API",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"LICENSE"
|
|
18
18
|
],
|
|
19
19
|
"scripts": {
|
|
20
|
-
"build": "mkdir -p dist && bun build ./sources/main.ts --outfile ./dist/main.js",
|
|
20
|
+
"build": "mkdir -p dist && bun build ./sources/main.ts --outfile ./dist/main.js --target node",
|
|
21
21
|
"build:binary": "bun build ./sources/main.ts --compile --outfile ./dist/brex",
|
|
22
22
|
"dev": "bun ./sources/main.ts",
|
|
23
23
|
"typecheck": "tsc --noEmit"
|