brex-cli 0.0.0-canary.38c7d2f → 0.0.0-canary.bfecee4

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.
Files changed (2) hide show
  1. package/dist/main.js +418 -93
  2. package/package.json +2 -2
package/dist/main.js CHANGED
@@ -2,9 +2,334 @@
2
2
  // @bun
3
3
 
4
4
  // 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";
5
+ var {existsSync, mkdirSync, readFileSync, writeFileSync, unlinkSync} = (() => ({}));
6
+
7
+ // node:os
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
8
333
  var CONFIG_DIR = join(homedir(), ".brex");
9
334
  var TOKEN_PATH = join(CONFIG_DIR, "token");
10
335
  var CONFIG_PATH = join(CONFIG_DIR, "config.json");
@@ -227,16 +552,16 @@ class BrexApiError2 extends Error {
227
552
 
228
553
  // sources/output.ts
229
554
  function parseOutputFlag(args) {
230
- let format = "table";
555
+ let format2 = "table";
231
556
  const remaining = [];
232
557
  for (const arg of args) {
233
558
  if (arg === "--json") {
234
- format = "json";
559
+ format2 = "json";
235
560
  continue;
236
561
  }
237
562
  remaining.push(arg);
238
563
  }
239
- return { format, args: remaining };
564
+ return { format: format2, args: remaining };
240
565
  }
241
566
  function printJson(data) {
242
567
  console.log(JSON.stringify(data, null, 2));
@@ -316,18 +641,18 @@ var accountsCommand = {
316
641
  usage: USAGE4,
317
642
  aliases: ["account", "acc"],
318
643
  run: async (args, context) => {
319
- const { format, args: remaining } = parseOutputFlag(args);
644
+ const { format: format2, args: remaining } = parseOutputFlag(args);
320
645
  const subcommand = remaining[0] ?? "list";
321
646
  switch (subcommand) {
322
647
  case "list":
323
- await listAccounts(context, parseListOptions(remaining.slice(1)), format);
648
+ await listAccounts(context, parseListOptions(remaining.slice(1)), format2);
324
649
  return;
325
650
  case "get": {
326
651
  const accountId = remaining[1];
327
652
  if (!accountId) {
328
653
  throw new Error("Missing account ID. Usage: brex accounts get <account-id> [--type cash|card]");
329
654
  }
330
- await getAccount(context, accountId, parseGetOptions(remaining.slice(2)), format);
655
+ await getAccount(context, accountId, parseGetOptions(remaining.slice(2)), format2);
331
656
  return;
332
657
  }
333
658
  default:
@@ -386,13 +711,13 @@ function parseGetOptions(args) {
386
711
  }
387
712
  return { type };
388
713
  }
389
- async function listAccounts(context, options, format) {
714
+ async function listAccounts(context, options, format2) {
390
715
  const cashPath = withCursor("/v2/accounts/cash", options.cursor);
391
716
  const cardPath = withCursor("/v2/accounts/card", options.cursor);
392
717
  if (options.type === "cash") {
393
718
  const cashResponse2 = await context.client.fetch(cashPath);
394
719
  const cashAccounts2 = extractItems(cashResponse2, ["items", "cash_accounts", "accounts"]);
395
- if (format === "json") {
720
+ if (format2 === "json") {
396
721
  printJson({ items: cashAccounts2, nextCursor: cashResponse2.next_cursor ?? null });
397
722
  return;
398
723
  }
@@ -406,7 +731,7 @@ Next cursor: ${cashResponse2.next_cursor}`);
406
731
  if (options.type === "card") {
407
732
  const cardResponse2 = await context.client.fetch(cardPath);
408
733
  const cardAccounts2 = extractItems(cardResponse2, ["items", "card_accounts", "accounts"]);
409
- if (format === "json") {
734
+ if (format2 === "json") {
410
735
  printJson({ items: cardAccounts2, nextCursor: cardResponse2.next_cursor ?? null });
411
736
  return;
412
737
  }
@@ -423,7 +748,7 @@ Next cursor: ${cardResponse2.next_cursor}`);
423
748
  ]);
424
749
  const cashAccounts = extractItems(cashResponse, ["items", "cash_accounts", "accounts"]);
425
750
  const cardAccounts = extractItems(cardResponse, ["items", "card_accounts", "accounts"]);
426
- if (format === "json") {
751
+ if (format2 === "json") {
427
752
  printJson({
428
753
  cash: { items: cashAccounts, nextCursor: cashResponse.next_cursor ?? null },
429
754
  card: { items: cardAccounts, nextCursor: cardResponse.next_cursor ?? null }
@@ -436,22 +761,22 @@ Next cursor: ${cardResponse2.next_cursor}`);
436
761
  ];
437
762
  printAccountsTable(rows);
438
763
  }
439
- async function getAccount(context, accountId, options, format) {
764
+ async function getAccount(context, accountId, options, format2) {
440
765
  const fetchCash = async () => context.client.fetch(`/v2/accounts/cash/${accountId}`);
441
766
  const fetchCard = async () => context.client.fetch(`/v2/accounts/card/${accountId}`);
442
767
  if (options.type === "cash") {
443
768
  const account = await fetchCash();
444
- renderAccount(account, "cash", format);
769
+ renderAccount(account, "cash", format2);
445
770
  return;
446
771
  }
447
772
  if (options.type === "card") {
448
773
  const account = await fetchCard();
449
- renderAccount(account, "card", format);
774
+ renderAccount(account, "card", format2);
450
775
  return;
451
776
  }
452
777
  try {
453
778
  const account = await fetchCash();
454
- renderAccount(account, "cash", format);
779
+ renderAccount(account, "cash", format2);
455
780
  return;
456
781
  } catch (error) {
457
782
  if (!(error instanceof BrexApiError2) || error.status !== 404) {
@@ -459,10 +784,10 @@ async function getAccount(context, accountId, options, format) {
459
784
  }
460
785
  }
461
786
  const cardAccount = await fetchCard();
462
- renderAccount(cardAccount, "card", format);
787
+ renderAccount(cardAccount, "card", format2);
463
788
  }
464
- function renderAccount(account, type, format) {
465
- if (format === "json") {
789
+ function renderAccount(account, type, format2) {
790
+ if (format2 === "json") {
466
791
  printJson(account);
467
792
  return;
468
793
  }
@@ -541,7 +866,7 @@ var transactionsCommand = {
541
866
  usage: USAGE5,
542
867
  aliases: ["tx", "txn"],
543
868
  run: async (args, context) => {
544
- const { format, args: remaining } = parseOutputFlag(args);
869
+ const { format: format2, args: remaining } = parseOutputFlag(args);
545
870
  if (remaining.length === 0) {
546
871
  throw new Error("Missing account ID. Usage: brex transactions <account-id>");
547
872
  }
@@ -552,7 +877,7 @@ var transactionsCommand = {
552
877
  if (!accountId2 || !transactionId) {
553
878
  throw new Error("Usage: brex transactions get <account-id> <transaction-id> [--type cash|card]");
554
879
  }
555
- await getTransaction(context, accountId2, transactionId, parseGetOptions2(remaining.slice(3)), format);
880
+ await getTransaction(context, accountId2, transactionId, parseGetOptions2(remaining.slice(3)), format2);
556
881
  return;
557
882
  }
558
883
  if (firstArg === "send") {
@@ -560,7 +885,7 @@ var transactionsCommand = {
560
885
  }
561
886
  const accountId = firstArg;
562
887
  const options = parseListOptions2(remaining.slice(1));
563
- await listTransactions(context, accountId, options, format);
888
+ await listTransactions(context, accountId, options, format2);
564
889
  }
565
890
  };
566
891
  function parseListOptions2(args) {
@@ -635,12 +960,12 @@ function parseGetOptions2(args) {
635
960
  }
636
961
  return { type };
637
962
  }
638
- async function listTransactions(context, accountId, options, format) {
963
+ async function listTransactions(context, accountId, options, format2) {
639
964
  const pathBase = options.type === "cash" ? `/v2/transactions/cash/${accountId}` : `/v2/transactions/card/${accountId}`;
640
965
  const path = withQuery(pathBase, options);
641
966
  const response = await context.client.fetch(path);
642
967
  const transactions = response.items ?? response.transactions ?? [];
643
- if (format === "json") {
968
+ if (format2 === "json") {
644
969
  printJson({ items: transactions, nextCursor: response.next_cursor ?? null });
645
970
  return;
646
971
  }
@@ -661,14 +986,14 @@ async function listTransactions(context, accountId, options, format) {
661
986
  Next cursor: ${response.next_cursor}`);
662
987
  }
663
988
  }
664
- async function getTransaction(context, accountId, transactionId, options, format) {
989
+ async function getTransaction(context, accountId, transactionId, options, format2) {
665
990
  const path = options.type === "cash" ? `/v2/transactions/cash/${accountId}/${transactionId}` : `/v2/transactions/card/${accountId}/${transactionId}`;
666
991
  const response = await context.client.fetch(path);
667
992
  const transaction = response.cash_transaction ?? response.card_transaction ?? response.transaction ?? response.item;
668
993
  if (!transaction) {
669
994
  throw new Error("Brex API returned an empty transaction payload.");
670
995
  }
671
- if (format === "json") {
996
+ if (format2 === "json") {
672
997
  printJson(transaction);
673
998
  return;
674
999
  }
@@ -720,21 +1045,21 @@ var transferCommand = {
720
1045
  description: "Create and inspect transfers.",
721
1046
  usage: USAGE6,
722
1047
  run: async (args, context) => {
723
- const { format, args: remaining } = parseOutputFlag(args);
1048
+ const { format: format2, args: remaining } = parseOutputFlag(args);
724
1049
  const subcommand = remaining[0];
725
1050
  if (subcommand === "get") {
726
1051
  const transferId = remaining[1];
727
1052
  if (!transferId)
728
1053
  throw new Error("Usage: brex transfer get <transfer-id>");
729
- await getTransfer(context, transferId, format);
1054
+ await getTransfer(context, transferId, format2);
730
1055
  return;
731
1056
  }
732
1057
  if (subcommand === "list") {
733
- await listTransfers(context, parseListTransferOptions(remaining.slice(1)), format);
1058
+ await listTransfers(context, parseListTransferOptions(remaining.slice(1)), format2);
734
1059
  return;
735
1060
  }
736
1061
  const options = parseCreateTransferOptions(remaining);
737
- await createTransfer(context, options, format);
1062
+ await createTransfer(context, options, format2);
738
1063
  }
739
1064
  };
740
1065
  function parseCreateTransferOptions(args) {
@@ -851,7 +1176,7 @@ function parseListTransferOptions(args) {
851
1176
  }
852
1177
  return options;
853
1178
  }
854
- async function createTransfer(context, options, format) {
1179
+ async function createTransfer(context, options, format2) {
855
1180
  const body = {
856
1181
  from_account: {
857
1182
  cash_account: {
@@ -877,22 +1202,22 @@ async function createTransfer(context, options, format) {
877
1202
  body: JSON.stringify(body)
878
1203
  });
879
1204
  const transfer = response.transfer ?? response.item ?? response;
880
- if (format === "json") {
1205
+ if (format2 === "json") {
881
1206
  printJson(transfer);
882
1207
  return;
883
1208
  }
884
1209
  printTransferDetails(transfer, "Transfer Created");
885
1210
  }
886
- async function getTransfer(context, transferId, format) {
1211
+ async function getTransfer(context, transferId, format2) {
887
1212
  const response = await context.client.fetch(`/v1/transfers/${transferId}`);
888
1213
  const transfer = response.transfer ?? response.item ?? response;
889
- if (format === "json") {
1214
+ if (format2 === "json") {
890
1215
  printJson(transfer);
891
1216
  return;
892
1217
  }
893
1218
  printTransferDetails(transfer, "Transfer Details");
894
1219
  }
895
- async function listTransfers(context, options, format) {
1220
+ async function listTransfers(context, options, format2) {
896
1221
  const params = new URLSearchParams;
897
1222
  if (options.cursor)
898
1223
  params.set("cursor", options.cursor);
@@ -908,7 +1233,7 @@ async function listTransfers(context, options, format) {
908
1233
  const path = query ? `/v1/transfers?${query}` : "/v1/transfers";
909
1234
  const response = await context.client.fetch(path);
910
1235
  const transfers = response.items ?? response.transfers ?? [];
911
- if (format === "json") {
1236
+ if (format2 === "json") {
912
1237
  printJson({ items: transfers, nextCursor: response.next_cursor ?? null });
913
1238
  return;
914
1239
  }
@@ -960,21 +1285,21 @@ var recipientsCommand = {
960
1285
  usage: USAGE7,
961
1286
  aliases: ["recipient", "recip"],
962
1287
  run: async (args, context) => {
963
- const { format, args: remaining } = parseOutputFlag(args);
1288
+ const { format: format2, args: remaining } = parseOutputFlag(args);
964
1289
  const subcommand = remaining[0] ?? "list";
965
1290
  switch (subcommand) {
966
1291
  case "list":
967
- await listRecipients(context, parseListOptions3(remaining.slice(1)), format);
1292
+ await listRecipients(context, parseListOptions3(remaining.slice(1)), format2);
968
1293
  return;
969
1294
  case "get": {
970
1295
  const recipientId = remaining[1];
971
1296
  if (!recipientId)
972
1297
  throw new Error("Missing recipient ID. Usage: brex recipients get <counterparty-id>");
973
- await getRecipient(context, recipientId, format);
1298
+ await getRecipient(context, recipientId, format2);
974
1299
  return;
975
1300
  }
976
1301
  case "add":
977
- await addRecipient(context, parseAddOptions(remaining.slice(1)), format);
1302
+ await addRecipient(context, parseAddOptions(remaining.slice(1)), format2);
978
1303
  return;
979
1304
  case "delete": {
980
1305
  const recipientId = remaining[1];
@@ -1091,7 +1416,7 @@ function parseAddOptions(args) {
1091
1416
  throw new Error("Missing required --routing");
1092
1417
  return { name, accountNumber, routingNumber, accountType, country, currency };
1093
1418
  }
1094
- async function listRecipients(context, options, format) {
1419
+ async function listRecipients(context, options, format2) {
1095
1420
  const params = new URLSearchParams;
1096
1421
  if (options.limit)
1097
1422
  params.set("limit", String(options.limit));
@@ -1103,7 +1428,7 @@ async function listRecipients(context, options, format) {
1103
1428
  const path = query ? `/v1/payment_counterparties?${query}` : "/v1/payment_counterparties";
1104
1429
  const response = await context.client.fetch(path);
1105
1430
  const recipients = response.items ?? response.payment_counterparties ?? [];
1106
- if (format === "json") {
1431
+ if (format2 === "json") {
1107
1432
  printJson({ items: recipients, nextCursor: response.next_cursor ?? null });
1108
1433
  return;
1109
1434
  }
@@ -1132,10 +1457,10 @@ async function listRecipients(context, options, format) {
1132
1457
  Next cursor: ${response.next_cursor}`);
1133
1458
  }
1134
1459
  }
1135
- async function getRecipient(context, recipientId, format) {
1460
+ async function getRecipient(context, recipientId, format2) {
1136
1461
  const response = await context.client.fetch(`/v1/payment_counterparties/${recipientId}`);
1137
1462
  const recipient = response.payment_counterparty ?? response.item ?? response;
1138
- if (format === "json") {
1463
+ if (format2 === "json") {
1139
1464
  printJson(recipient);
1140
1465
  return;
1141
1466
  }
@@ -1155,7 +1480,7 @@ async function getRecipient(context, recipientId, format) {
1155
1480
  if (bank?.currency)
1156
1481
  console.log(`Currency: ${bank.currency}`);
1157
1482
  }
1158
- async function addRecipient(context, options, format) {
1483
+ async function addRecipient(context, options, format2) {
1159
1484
  const body = {
1160
1485
  name: options.name,
1161
1486
  payment_instrument: {
@@ -1173,7 +1498,7 @@ async function addRecipient(context, options, format) {
1173
1498
  body: JSON.stringify(body)
1174
1499
  });
1175
1500
  const recipient = response.payment_counterparty ?? response.item ?? response;
1176
- if (format === "json") {
1501
+ if (format2 === "json") {
1177
1502
  printJson(recipient);
1178
1503
  return;
1179
1504
  }
@@ -1199,22 +1524,22 @@ var cardsCommand = {
1199
1524
  usage: USAGE8,
1200
1525
  aliases: ["card"],
1201
1526
  run: async (args, context) => {
1202
- const { format, args: remaining } = parseOutputFlag(args);
1527
+ const { format: format2, args: remaining } = parseOutputFlag(args);
1203
1528
  const subcommand = remaining[0] ?? "list";
1204
1529
  if (subcommand === "get") {
1205
1530
  const cardId = remaining[1];
1206
1531
  if (!cardId) {
1207
1532
  throw new Error("Usage: brex cards get <card-id>");
1208
1533
  }
1209
- await getCard(context, cardId, format);
1534
+ await getCard(context, cardId, format2);
1210
1535
  return;
1211
1536
  }
1212
1537
  if (subcommand !== "list" && !subcommand.startsWith("-")) {
1213
- await getCard(context, subcommand, format);
1538
+ await getCard(context, subcommand, format2);
1214
1539
  return;
1215
1540
  }
1216
1541
  const listArgs = subcommand === "list" ? remaining.slice(1) : remaining;
1217
- await listCards(context, parseListOptions4(listArgs), format);
1542
+ await listCards(context, parseListOptions4(listArgs), format2);
1218
1543
  }
1219
1544
  };
1220
1545
  function parseListOptions4(args) {
@@ -1256,7 +1581,7 @@ function parseListOptions4(args) {
1256
1581
  }
1257
1582
  return { userId, cursor, limit };
1258
1583
  }
1259
- async function listCards(context, options, format) {
1584
+ async function listCards(context, options, format2) {
1260
1585
  const params = new URLSearchParams;
1261
1586
  if (options.userId)
1262
1587
  params.set("user_id", options.userId);
@@ -1268,7 +1593,7 @@ async function listCards(context, options, format) {
1268
1593
  const path = query ? `/v2/cards?${query}` : "/v2/cards";
1269
1594
  const response = await context.client.fetch(path);
1270
1595
  const cards = response.items ?? response.cards ?? [];
1271
- if (format === "json") {
1596
+ if (format2 === "json") {
1272
1597
  printJson({ items: cards, nextCursor: response.next_cursor ?? null });
1273
1598
  return;
1274
1599
  }
@@ -1296,10 +1621,10 @@ async function listCards(context, options, format) {
1296
1621
  Next cursor: ${response.next_cursor}`);
1297
1622
  }
1298
1623
  }
1299
- async function getCard(context, cardId, format) {
1624
+ async function getCard(context, cardId, format2) {
1300
1625
  const response = await context.client.fetch(`/v2/cards/${cardId}`);
1301
1626
  const card = response.card ?? response.item ?? response;
1302
- if (format === "json") {
1627
+ if (format2 === "json") {
1303
1628
  printJson(card);
1304
1629
  return;
1305
1630
  }
@@ -1330,7 +1655,7 @@ var statementsCommand = {
1330
1655
  usage: USAGE9,
1331
1656
  aliases: ["statement"],
1332
1657
  run: async (args, context) => {
1333
- const { format, args: remaining } = parseOutputFlag(args);
1658
+ const { format: format2, args: remaining } = parseOutputFlag(args);
1334
1659
  const firstArg = remaining[0] ?? "list";
1335
1660
  if (firstArg === "get") {
1336
1661
  const statementId = remaining[1];
@@ -1338,11 +1663,11 @@ var statementsCommand = {
1338
1663
  throw new Error("Usage: brex statements get <statement-id> [--scope primary|additional] [--account-id <id>]");
1339
1664
  }
1340
1665
  const options2 = parseSharedOptions(remaining.slice(2));
1341
- await getStatement(context, statementId, options2, format);
1666
+ await getStatement(context, statementId, options2, format2);
1342
1667
  return;
1343
1668
  }
1344
1669
  const options = parseListOptions5(remaining.slice(firstArg === "list" ? 1 : 0));
1345
- await listStatements(context, options, format);
1670
+ await listStatements(context, options, format2);
1346
1671
  }
1347
1672
  };
1348
1673
  function parseListOptions5(args) {
@@ -1399,11 +1724,11 @@ function parseSharedOptions(args) {
1399
1724
  }
1400
1725
  return { scope, accountId };
1401
1726
  }
1402
- async function listStatements(context, options, format) {
1727
+ async function listStatements(context, options, format2) {
1403
1728
  const path = options.scope === "primary" ? withCursor2("/v2/accounts/card/primary/statements", options.cursor) : withCursor2(`/v2/accounts/card/additional/${options.accountId}/statements`, options.cursor);
1404
1729
  const response = await context.client.fetch(path);
1405
1730
  const statements = response.items ?? response.statements ?? [];
1406
- if (format === "json") {
1731
+ if (format2 === "json") {
1407
1732
  printJson({ items: statements, nextCursor: response.next_cursor ?? null });
1408
1733
  return;
1409
1734
  }
@@ -1431,14 +1756,14 @@ async function listStatements(context, options, format) {
1431
1756
  Next cursor: ${response.next_cursor}`);
1432
1757
  }
1433
1758
  }
1434
- async function getStatement(context, statementId, options, format) {
1759
+ async function getStatement(context, statementId, options, format2) {
1435
1760
  const path = options.scope === "primary" ? `/v2/accounts/card/primary/statements/${statementId}` : `/v2/accounts/card/additional/${options.accountId}/statements/${statementId}`;
1436
1761
  const response = await context.client.fetch(path);
1437
1762
  const statement = response.account_statement ?? response.statement ?? response.item;
1438
1763
  if (!statement) {
1439
1764
  throw new Error("Brex API returned an empty statement payload.");
1440
1765
  }
1441
- if (format === "json") {
1766
+ if (format2 === "json") {
1442
1767
  printJson(statement);
1443
1768
  return;
1444
1769
  }
@@ -1471,27 +1796,27 @@ var webhooksCommand = {
1471
1796
  usage: USAGE10,
1472
1797
  aliases: ["webhook", "wh"],
1473
1798
  run: async (args, context) => {
1474
- const { format, args: remaining } = parseOutputFlag(args);
1799
+ const { format: format2, args: remaining } = parseOutputFlag(args);
1475
1800
  const subcommand = remaining[0] ?? "list";
1476
1801
  switch (subcommand) {
1477
1802
  case "list":
1478
- await listWebhooks(context, parseListOptions6(remaining.slice(1)), format);
1803
+ await listWebhooks(context, parseListOptions6(remaining.slice(1)), format2);
1479
1804
  return;
1480
1805
  case "get": {
1481
1806
  const webhookId = remaining[1];
1482
1807
  if (!webhookId)
1483
1808
  throw new Error("Missing webhook ID. Usage: brex webhooks get <webhook-id>");
1484
- await getWebhook(context, webhookId, format);
1809
+ await getWebhook(context, webhookId, format2);
1485
1810
  return;
1486
1811
  }
1487
1812
  case "create":
1488
- await createWebhook(context, parseCreateOptions(remaining.slice(1)), format);
1813
+ await createWebhook(context, parseCreateOptions(remaining.slice(1)), format2);
1489
1814
  return;
1490
1815
  case "update": {
1491
1816
  const webhookId = remaining[1];
1492
1817
  if (!webhookId)
1493
1818
  throw new Error("Missing webhook ID. Usage: brex webhooks update <webhook-id> ...");
1494
- await updateWebhook(context, webhookId, parseUpdateOptions(remaining.slice(2)), format);
1819
+ await updateWebhook(context, webhookId, parseUpdateOptions(remaining.slice(2)), format2);
1495
1820
  return;
1496
1821
  }
1497
1822
  case "delete": {
@@ -1608,7 +1933,7 @@ function parseUpdateOptions(args) {
1608
1933
  }
1609
1934
  return options;
1610
1935
  }
1611
- async function listWebhooks(context, options, format) {
1936
+ async function listWebhooks(context, options, format2) {
1612
1937
  const params = new URLSearchParams;
1613
1938
  if (options.cursor)
1614
1939
  params.set("cursor", options.cursor);
@@ -1618,7 +1943,7 @@ async function listWebhooks(context, options, format) {
1618
1943
  const path = query ? `/v1/webhooks?${query}` : "/v1/webhooks";
1619
1944
  const response = await context.client.fetch(path);
1620
1945
  const webhooks = response.items ?? response.webhooks ?? [];
1621
- if (format === "json") {
1946
+ if (format2 === "json") {
1622
1947
  printJson({ items: webhooks, nextCursor: response.next_cursor ?? null });
1623
1948
  return;
1624
1949
  }
@@ -1642,10 +1967,10 @@ async function listWebhooks(context, options, format) {
1642
1967
  Next cursor: ${response.next_cursor}`);
1643
1968
  }
1644
1969
  }
1645
- async function getWebhook(context, webhookId, format) {
1970
+ async function getWebhook(context, webhookId, format2) {
1646
1971
  const response = await context.client.fetch(`/v1/webhooks/${webhookId}`);
1647
1972
  const webhook = response.webhook ?? response.item ?? response;
1648
- if (format === "json") {
1973
+ if (format2 === "json") {
1649
1974
  printJson(webhook);
1650
1975
  return;
1651
1976
  }
@@ -1657,7 +1982,7 @@ async function getWebhook(context, webhookId, format) {
1657
1982
  console.log(`Status: ${webhook.status ?? "-"}`);
1658
1983
  console.log(`Events: ${events.length > 0 ? events.join(", ") : "-"}`);
1659
1984
  }
1660
- async function createWebhook(context, options, format) {
1985
+ async function createWebhook(context, options, format2) {
1661
1986
  const body = {
1662
1987
  url: options.url
1663
1988
  };
@@ -1674,7 +1999,7 @@ async function createWebhook(context, options, format) {
1674
1999
  body: JSON.stringify(body)
1675
2000
  });
1676
2001
  const webhook = response.webhook ?? response.item ?? response;
1677
- if (format === "json") {
2002
+ if (format2 === "json") {
1678
2003
  printJson(webhook);
1679
2004
  return;
1680
2005
  }
@@ -1684,7 +2009,7 @@ async function createWebhook(context, options, format) {
1684
2009
  console.log(`URL: ${webhook.url ?? "-"}`);
1685
2010
  console.log(`Status: ${webhook.status ?? "-"}`);
1686
2011
  }
1687
- async function updateWebhook(context, webhookId, options, format) {
2012
+ async function updateWebhook(context, webhookId, options, format2) {
1688
2013
  const body = {};
1689
2014
  if (options.url)
1690
2015
  body.url = options.url;
@@ -1701,7 +2026,7 @@ async function updateWebhook(context, webhookId, options, format) {
1701
2026
  body: JSON.stringify(body)
1702
2027
  });
1703
2028
  const webhook = response.webhook ?? response.item ?? response;
1704
- if (format === "json") {
2029
+ if (format2 === "json") {
1705
2030
  printJson(webhook);
1706
2031
  return;
1707
2032
  }
@@ -1727,21 +2052,21 @@ var eventsCommand = {
1727
2052
  usage: USAGE11,
1728
2053
  aliases: ["event"],
1729
2054
  run: async (args, context) => {
1730
- const { format, args: remaining } = parseOutputFlag(args);
2055
+ const { format: format2, args: remaining } = parseOutputFlag(args);
1731
2056
  const subcommand = remaining[0] ?? "list";
1732
2057
  if (subcommand === "list") {
1733
- await listEvents(context, parseListOptions7(remaining.slice(1)), format);
2058
+ await listEvents(context, parseListOptions7(remaining.slice(1)), format2);
1734
2059
  return;
1735
2060
  }
1736
2061
  if (subcommand === "get") {
1737
2062
  const eventId = remaining[1];
1738
2063
  if (!eventId)
1739
2064
  throw new Error("Missing event ID. Usage: brex events get <event-id>");
1740
- await getEvent(context, eventId, format);
2065
+ await getEvent(context, eventId, format2);
1741
2066
  return;
1742
2067
  }
1743
2068
  if (!subcommand.startsWith("-")) {
1744
- await getEvent(context, subcommand, format);
2069
+ await getEvent(context, subcommand, format2);
1745
2070
  return;
1746
2071
  }
1747
2072
  throw new Error(`Unknown subcommand: ${subcommand}`);
@@ -1798,7 +2123,7 @@ function parseListOptions7(args) {
1798
2123
  }
1799
2124
  return options;
1800
2125
  }
1801
- async function listEvents(context, options, format) {
2126
+ async function listEvents(context, options, format2) {
1802
2127
  const params = new URLSearchParams;
1803
2128
  if (options.eventType)
1804
2129
  params.set("event_type", options.eventType);
@@ -1814,7 +2139,7 @@ async function listEvents(context, options, format) {
1814
2139
  const path = query ? `/v1/events?${query}` : "/v1/events";
1815
2140
  const response = await context.client.fetch(path);
1816
2141
  const events = response.items ?? response.events ?? [];
1817
- if (format === "json") {
2142
+ if (format2 === "json") {
1818
2143
  printJson({ items: events, nextCursor: response.next_cursor ?? null });
1819
2144
  return;
1820
2145
  }
@@ -1838,10 +2163,10 @@ async function listEvents(context, options, format) {
1838
2163
  Next cursor: ${response.next_cursor}`);
1839
2164
  }
1840
2165
  }
1841
- async function getEvent(context, eventId, format) {
2166
+ async function getEvent(context, eventId, format2) {
1842
2167
  const response = await context.client.fetch(`/v1/events/${eventId}`);
1843
2168
  const event = response.event ?? response.item ?? response;
1844
- if (format === "json") {
2169
+ if (format2 === "json") {
1845
2170
  printJson(event);
1846
2171
  return;
1847
2172
  }
@@ -1865,10 +2190,10 @@ var organizationCommand = {
1865
2190
  usage: USAGE12,
1866
2191
  aliases: ["org"],
1867
2192
  run: async (args, context) => {
1868
- const { format } = parseOutputFlag(args);
2193
+ const { format: format2 } = parseOutputFlag(args);
1869
2194
  const response = await context.client.fetch("/v2/company");
1870
2195
  const company = response.company ?? response.item ?? response;
1871
- if (format === "json") {
2196
+ if (format2 === "json") {
1872
2197
  printJson(company);
1873
2198
  return;
1874
2199
  }
@@ -1909,22 +2234,22 @@ var usersCommand = {
1909
2234
  usage: USAGE13,
1910
2235
  aliases: ["user"],
1911
2236
  run: async (args, context) => {
1912
- const { format, args: remaining } = parseOutputFlag(args);
2237
+ const { format: format2, args: remaining } = parseOutputFlag(args);
1913
2238
  const subcommand = remaining[0] ?? "list";
1914
2239
  switch (subcommand) {
1915
2240
  case "list":
1916
- await listUsers(context, parseListOptions8(remaining.slice(1)), format);
2241
+ await listUsers(context, parseListOptions8(remaining.slice(1)), format2);
1917
2242
  return;
1918
2243
  case "get": {
1919
2244
  const userId = remaining[1];
1920
2245
  if (!userId)
1921
2246
  throw new Error("Missing user ID. Usage: brex users get <user-id>");
1922
- await getUser(context, userId, format);
2247
+ await getUser(context, userId, format2);
1923
2248
  return;
1924
2249
  }
1925
2250
  default:
1926
2251
  if (!subcommand.startsWith("-")) {
1927
- await getUser(context, subcommand, format);
2252
+ await getUser(context, subcommand, format2);
1928
2253
  return;
1929
2254
  }
1930
2255
  throw new Error(`Unknown subcommand: ${subcommand}`);
@@ -1958,7 +2283,7 @@ function parseListOptions8(args) {
1958
2283
  }
1959
2284
  return { cursor, email };
1960
2285
  }
1961
- async function listUsers(context, options, format) {
2286
+ async function listUsers(context, options, format2) {
1962
2287
  const params = new URLSearchParams;
1963
2288
  if (options.cursor)
1964
2289
  params.set("cursor", options.cursor);
@@ -1968,7 +2293,7 @@ async function listUsers(context, options, format) {
1968
2293
  const path = query ? `/v2/users?${query}` : "/v2/users";
1969
2294
  const response = await context.client.fetch(path);
1970
2295
  const users = response.items ?? response.users ?? [];
1971
- if (format === "json") {
2296
+ if (format2 === "json") {
1972
2297
  printJson({ items: users, nextCursor: response.next_cursor ?? null });
1973
2298
  return;
1974
2299
  }
@@ -1996,10 +2321,10 @@ async function listUsers(context, options, format) {
1996
2321
  Next cursor: ${response.next_cursor}`);
1997
2322
  }
1998
2323
  }
1999
- async function getUser(context, userId, format) {
2324
+ async function getUser(context, userId, format2) {
2000
2325
  const response = await context.client.fetch(`/v2/users/${userId}`);
2001
2326
  const user = response.user ?? response.item ?? response;
2002
- if (format === "json") {
2327
+ if (format2 === "json") {
2003
2328
  printJson(user);
2004
2329
  return;
2005
2330
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brex-cli",
3
- "version": "0.0.0-canary.38c7d2f",
3
+ "version": "0.0.0-canary.bfecee4",
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 --target node",
20
+ "build": "mkdir -p dist && bun build ./sources/main.ts --outfile ./dist/main.js",
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"