-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccounts.ts
More file actions
40 lines (32 loc) · 1.22 KB
/
Copy pathaccounts.ts
File metadata and controls
40 lines (32 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { connectAndSync, logError, promptTan, type BankOptions } from './connection.js';
export async function listAccounts(opts: BankOptions): Promise<void> {
const { client, accounts } = await connectAndSync(opts);
const results: any[] = [];
for (const acct of accounts) {
const entry: any = {
accountNumber: acct.accountNumber,
iban: acct.iban || null,
bic: acct.bic || null,
type: acct.accountType || null,
holder: acct.accountHolder || null,
};
if (client.canGetAccountBalance(acct.accountNumber)) {
let balanceResponse = await client.getAccountBalance(acct.accountNumber);
if (balanceResponse.requiresTan) {
const tan = await promptTan(
balanceResponse.tanChallenge || 'Please approve in your TAN app',
);
balanceResponse = await client.getAccountBalanceWithTan(
balanceResponse.tanReference!,
tan,
);
}
if (balanceResponse.success && balanceResponse.balance) {
entry.currency = balanceResponse.balance.currency || 'EUR';
entry.balance = balanceResponse.balance.balance;
}
}
results.push(entry);
}
process.stdout.write(JSON.stringify(results, null, 2) + '\n');
}