-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
106 lines (92 loc) · 3.05 KB
/
Copy pathindex.ts
File metadata and controls
106 lines (92 loc) · 3.05 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env node
import { Command } from 'commander';
import { executeTransfer } from './transfer.js';
import { listAccounts } from './accounts.js';
import { getStatements } from './statements.js';
import { formatError, type BankOptions } from './connection.js';
import { loadConfig, initConfig } from './config.js';
loadConfig();
const program = new Command();
program
.name('fints-cli')
.description('FinTS 3.0 banking CLI')
.version('1.1.0');
function getBankOptions(): BankOptions {
const blz = process.env.FVB_BLZ;
const user = process.env.FVB_USER;
const pin = process.env.FVB_PIN;
const url = process.env.FVB_URL;
const productId = process.env.FVB_PRODUCT_ID;
const missing = [];
if (!blz) missing.push('FVB_BLZ');
if (!user) missing.push('FVB_USER');
if (!pin) missing.push('FVB_PIN');
if (!url) missing.push('FVB_URL');
if (!productId) missing.push('FVB_PRODUCT_ID');
if (missing.length > 0) {
process.stderr.write(
JSON.stringify({
error: `Missing environment variables: ${missing.join(', ')}. Run "fints-cli init" to set up your config.`,
}) + '\n',
);
process.exit(1);
}
return { blz: blz!, user: user!, pin: pin!, url: url!, productId: productId! };
}
function handleError(err: any): never {
const detail = formatError(err);
process.stderr.write(JSON.stringify({ error: detail }, null, 2) + '\n');
process.exit(1);
}
program
.command('transfer')
.description('SEPA credit transfer')
.requiredOption('--recipient <name>', 'Recipient name')
.requiredOption('--iban <iban>', 'Recipient IBAN')
.option('--bic <bic>', 'Recipient BIC (optional, resolved by bank)')
.requiredOption('--amount <amount>', 'Amount in EUR (e.g. 12.50)')
.option('--purpose <text>', 'Payment purpose / reference')
.option('--source-iban <iban>', 'Source account IBAN (default: first account)')
.option('--instant', 'Use SEPA Instant Payment (Echtzeitüberweisung)')
.action(async (opts) => {
const bank = getBankOptions();
await executeTransfer({
...bank,
recipient: opts.recipient,
iban: opts.iban,
bic: opts.bic,
amount: opts.amount,
purpose: opts.purpose,
sourceIban: opts.sourceIban,
instant: opts.instant,
});
});
program
.command('accounts')
.description('List accounts and balances')
.action(async () => {
const bank = getBankOptions();
await listAccounts(bank);
});
program
.command('statements')
.description('Get account statements / transactions')
.option('--account <iban-or-number>', 'Account IBAN or number (default: first account)')
.option('--from <date>', 'Start date (YYYY-MM-DD)')
.option('--to <date>', 'End date (YYYY-MM-DD)')
.action(async (opts) => {
const bank = getBankOptions();
await getStatements({
...bank,
account: opts.account,
from: opts.from,
to: opts.to,
});
});
program
.command('init')
.description('Interactive setup — creates ~/.config/fints-cli/config.env')
.action(async () => {
await initConfig();
});
program.parseAsync().catch(handleError);