@dilllxd/simplefin-cli 0.1.0
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/LICENSE +19 -0
- package/README.md +152 -0
- package/bin/simplefin.js +454 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# 🪙 simplefin-cli
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@dilllxd/simplefin-cli)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
[](https://nodejs.org)
|
|
6
|
+
|
|
7
|
+
A CLI tool for accessing financial data via [SimpleFIN Bridge](https://beta-bridge.simplefin.org/).
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## ✨ Why simplefin-cli?
|
|
12
|
+
|
|
13
|
+
[SimpleFIN Bridge](https://beta-bridge.simplefin.org/) provides a secure way to access financial data.
|
|
14
|
+
`simplefin-cli` gives you full command-line access without a GUI.
|
|
15
|
+
|
|
16
|
+
✅ Non-interactive (100% automatable)
|
|
17
|
+
✅ Cross-platform (Linux, macOS, Windows)
|
|
18
|
+
✅ Full SimpleFIN protocol support
|
|
19
|
+
✅ JSON output for scripting
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## 🚀 Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install -g @dilllxd/simplefin-cli
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## 💡 Quick Start
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
# Connect with a setup token
|
|
35
|
+
simplefin connect --token YOUR_SETUP_TOKEN
|
|
36
|
+
|
|
37
|
+
# List accounts
|
|
38
|
+
simplefin accounts
|
|
39
|
+
|
|
40
|
+
# View transactions
|
|
41
|
+
simplefin transactions
|
|
42
|
+
|
|
43
|
+
# Get transactions as JSON
|
|
44
|
+
simplefin transactions --json
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Get a setup token at https://beta-bridge.simplefin.org/my-account/tokens/create
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## 📖 Commands
|
|
52
|
+
|
|
53
|
+
### `simplefin connect`
|
|
54
|
+
|
|
55
|
+
Connect to SimpleFIN Bridge using a setup token.
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
simplefin connect --token <setup-token>
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Token can also be provided via `SIMPLEFIN_SETUP_TOKEN` environment variable.
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
### `simplefin disconnect`
|
|
66
|
+
|
|
67
|
+
Remove saved credentials.
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
simplefin disconnect
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
### `simplefin status`
|
|
76
|
+
|
|
77
|
+
Check connection status.
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
simplefin status
|
|
81
|
+
simplefin status --json
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
### `simplefin accounts`
|
|
87
|
+
|
|
88
|
+
List connected accounts.
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
simplefin accounts
|
|
92
|
+
simplefin accounts --json
|
|
93
|
+
simplefin accounts --balances-only
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
### `simplefin transactions`
|
|
99
|
+
|
|
100
|
+
List transactions.
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
simplefin transactions # Last 30 days
|
|
104
|
+
simplefin transactions --days 7 # Last 7 days
|
|
105
|
+
simplefin transactions --json # JSON output
|
|
106
|
+
simplefin transactions --start-date 2026-01-01
|
|
107
|
+
simplefin transactions --end-date 2026-01-31
|
|
108
|
+
simplefin transactions --account ACT-12345
|
|
109
|
+
simplefin transactions --pending
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
### `simplefin info`
|
|
115
|
+
|
|
116
|
+
Show server information.
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
simplefin info
|
|
120
|
+
simplefin info --json
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## 🔧 Configuration
|
|
126
|
+
|
|
127
|
+
Credentials stored in OS-appropriate location:
|
|
128
|
+
|
|
129
|
+
| OS | Location |
|
|
130
|
+
|---|---|
|
|
131
|
+
| Linux | `~/.config/simplefin-cli/connection.json` |
|
|
132
|
+
| macOS | `~/Library/Application Support/simplefin-cli/` |
|
|
133
|
+
| Windows | `%APPDATA%\simplefin-cli\` |
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## 🧱 Project Structure
|
|
138
|
+
|
|
139
|
+
```
|
|
140
|
+
simplefin-cli/
|
|
141
|
+
├── bin/
|
|
142
|
+
│ └── simplefin.js # Main CLI entry point
|
|
143
|
+
├── LICENSE
|
|
144
|
+
├── package.json
|
|
145
|
+
└── README.md
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## 🪪 License
|
|
151
|
+
|
|
152
|
+
MIT
|
package/bin/simplefin.js
ADDED
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
const { Command } = require('commander');
|
|
2
|
+
const axios = require('axios');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const os = require('os');
|
|
6
|
+
|
|
7
|
+
const program = new Command();
|
|
8
|
+
|
|
9
|
+
function getConfigDir() {
|
|
10
|
+
const appName = 'simplefin-cli';
|
|
11
|
+
|
|
12
|
+
switch (process.platform) {
|
|
13
|
+
case 'darwin': // macOS
|
|
14
|
+
return path.join(os.homedir(), 'Library', 'Application Support', appName);
|
|
15
|
+
case 'win32': // Windows
|
|
16
|
+
return path.join(process.env.APPDATA || path.join(os.homedir(), 'AppData', 'Roaming'), appName);
|
|
17
|
+
default: // Linux, BSD, etc.
|
|
18
|
+
if (process.env.XDG_CONFIG_HOME) {
|
|
19
|
+
return path.join(process.env.XDG_CONFIG_HOME, appName);
|
|
20
|
+
}
|
|
21
|
+
return path.join(os.homedir(), '.config', appName);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function getConnectionPath() {
|
|
26
|
+
return path.join(getConfigDir(), 'connection.json');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function loadConnection() {
|
|
30
|
+
try {
|
|
31
|
+
const data = fs.readFileSync(getConnectionPath(), 'utf-8');
|
|
32
|
+
return JSON.parse(data);
|
|
33
|
+
} catch {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function saveConnection(accessUrl, username, password) {
|
|
39
|
+
fs.mkdirSync(getConfigDir(), { recursive: true });
|
|
40
|
+
const connection = {
|
|
41
|
+
access_url: accessUrl,
|
|
42
|
+
username,
|
|
43
|
+
password,
|
|
44
|
+
created_at: new Date().toISOString(),
|
|
45
|
+
};
|
|
46
|
+
fs.writeFileSync(getConnectionPath(), JSON.stringify(connection, null, 2));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function deleteConnection() {
|
|
50
|
+
try {
|
|
51
|
+
fs.unlinkSync(getConnectionPath());
|
|
52
|
+
} catch (e) {
|
|
53
|
+
// ignore
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function parseAuthFromUrl(accessUrl) {
|
|
58
|
+
const match = accessUrl.match(/:\/\/([^:]+):([^@]+)@/);
|
|
59
|
+
if (match) {
|
|
60
|
+
return {
|
|
61
|
+
username: match[1],
|
|
62
|
+
password: match[2],
|
|
63
|
+
baseUrl: accessUrl.replace(/:\/\/[^:]+:[^@]+@/, '://'),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function claimAccessUrl(setupToken) {
|
|
70
|
+
const claimUrl = Buffer.from(setupToken, 'base64').toString('utf-8');
|
|
71
|
+
|
|
72
|
+
const response = await axios.post(claimUrl, '', {
|
|
73
|
+
headers: { 'Content-Length': '0' },
|
|
74
|
+
timeout: 10000,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
if (response.status === 403) {
|
|
78
|
+
throw new Error('Token is invalid or has already been used');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (response.status !== 200) {
|
|
82
|
+
throw new Error(`Unexpected response: ${response.status}`);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const accessUrl = response.data.trim();
|
|
86
|
+
if (!accessUrl) {
|
|
87
|
+
throw new Error('Empty response from server');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return accessUrl;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function getInfo(baseUrl) {
|
|
94
|
+
const response = await axios.get(`${baseUrl}/info`);
|
|
95
|
+
return response.data;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async function getAccounts(options) {
|
|
99
|
+
const params = new URLSearchParams();
|
|
100
|
+
|
|
101
|
+
if (options.startDate) params.append('start-date', options.startDate);
|
|
102
|
+
if (options.endDate) params.append('end-date', options.endDate);
|
|
103
|
+
if (options.pending) params.append('pending', '1');
|
|
104
|
+
if (options.account) params.append('account', options.account);
|
|
105
|
+
if (options.balancesOnly) params.append('balances-only', '1');
|
|
106
|
+
|
|
107
|
+
const url = `${options.baseUrl}/accounts${params.toString() ? '?' + params.toString() : ''}`;
|
|
108
|
+
|
|
109
|
+
const response = await axios.get(url, {
|
|
110
|
+
auth: { username: options.username, password: options.password },
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
if (response.status === 403) {
|
|
114
|
+
throw new Error('Authentication failed - access may be revoked');
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (response.status === 402) {
|
|
118
|
+
throw new Error('Payment required');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return response.data;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function formatDate(timestamp) {
|
|
125
|
+
if (!timestamp) return 'N/A';
|
|
126
|
+
const date = new Date(timestamp * 1000);
|
|
127
|
+
return date.toLocaleString('en-US', {
|
|
128
|
+
month: 'short', day: 'numeric', year: 'numeric',
|
|
129
|
+
hour: 'numeric', minute: '2-digit', hour12: true,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function formatDateFull(timestamp) {
|
|
134
|
+
if (!timestamp) return 'N/A';
|
|
135
|
+
const date = new Date(timestamp * 1000);
|
|
136
|
+
return date.toLocaleString('en-US', {
|
|
137
|
+
weekday: 'short', month: 'short', day: 'numeric', year: 'numeric',
|
|
138
|
+
hour: 'numeric', minute: '2-digit', hour12: true,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function formatDateShort(timestamp) {
|
|
143
|
+
if (!timestamp) return '';
|
|
144
|
+
const date = new Date(timestamp * 1000);
|
|
145
|
+
return date.toLocaleDateString('en-US', { month: '2-digit', day: '2-digit' });
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function truncate(str, len) {
|
|
149
|
+
if (!str) return '';
|
|
150
|
+
return str.length > len ? str.slice(0, len - 3) + '...' : str;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
program.name('simplefin').description('SimpleFIN CLI - Access your financial data');
|
|
154
|
+
|
|
155
|
+
// ===== INFO COMMAND =====
|
|
156
|
+
program.command('info')
|
|
157
|
+
.description('Get SimpleFIN server information')
|
|
158
|
+
.option('--json', 'Output as JSON')
|
|
159
|
+
.action(async (options) => {
|
|
160
|
+
const conn = loadConnection();
|
|
161
|
+
if (!conn) {
|
|
162
|
+
console.log('Not connected');
|
|
163
|
+
console.log("Run 'simplefin connect' first");
|
|
164
|
+
process.exit(1);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
try {
|
|
168
|
+
const data = await getInfo(conn.access_url);
|
|
169
|
+
|
|
170
|
+
if (options.json) {
|
|
171
|
+
console.log(JSON.stringify(data, null, 2));
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
console.log('Server Info');
|
|
176
|
+
console.log('-----------');
|
|
177
|
+
console.log(`Supported versions: ${(data.versions || []).join(', ')}`);
|
|
178
|
+
} catch (error) {
|
|
179
|
+
console.error('Error:', error.message);
|
|
180
|
+
process.exit(1);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
// ===== CONNECT COMMAND =====
|
|
185
|
+
program.command('connect')
|
|
186
|
+
.description('Connect to SimpleFIN Bridge')
|
|
187
|
+
.option('-t, --token <token>', 'Setup token (or use SIMPLEFIN_SETUP_TOKEN env var)')
|
|
188
|
+
.action(async (options) => {
|
|
189
|
+
let setupToken = options.token || process.env.SIMPLEFIN_SETUP_TOKEN;
|
|
190
|
+
|
|
191
|
+
if (!setupToken) {
|
|
192
|
+
console.log('Error: Setup token required');
|
|
193
|
+
console.log('Provide via:');
|
|
194
|
+
console.log(' -t, --token option: simplefin connect --token <token>');
|
|
195
|
+
console.log(' Environment variable: export SIMPLEFIN_SETUP_TOKEN=<token>');
|
|
196
|
+
console.log('\nGet a token at: https://bridge.simplefin.org/simplefin/create');
|
|
197
|
+
process.exit(1);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
console.log('Connecting to SimpleFIN Bridge...');
|
|
201
|
+
|
|
202
|
+
try {
|
|
203
|
+
const accessUrl = await claimAccessUrl(setupToken);
|
|
204
|
+
const auth = parseAuthFromUrl(accessUrl);
|
|
205
|
+
if (!auth) {
|
|
206
|
+
throw new Error('Could not parse credentials from Access URL');
|
|
207
|
+
}
|
|
208
|
+
saveConnection(auth.baseUrl, auth.username, auth.password);
|
|
209
|
+
console.log('Connected successfully!');
|
|
210
|
+
console.log('\nNext steps:');
|
|
211
|
+
console.log(' simplefin info - Server info');
|
|
212
|
+
console.log(' simplefin accounts - List your accounts');
|
|
213
|
+
console.log(' simplefin transactions - View transactions');
|
|
214
|
+
} catch (error) {
|
|
215
|
+
console.error('Error:', error.message);
|
|
216
|
+
process.exit(1);
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
// ===== DISCONNECT COMMAND =====
|
|
221
|
+
program.command('disconnect')
|
|
222
|
+
.description('Disconnect from SimpleFIN Bridge')
|
|
223
|
+
.action(() => {
|
|
224
|
+
deleteConnection();
|
|
225
|
+
console.log('Disconnected successfully');
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
// ===== STATUS COMMAND =====
|
|
229
|
+
program.command('status')
|
|
230
|
+
.description('Check connection status')
|
|
231
|
+
.option('--json', 'Output as JSON')
|
|
232
|
+
.action((options) => {
|
|
233
|
+
const conn = loadConnection();
|
|
234
|
+
if (!conn) {
|
|
235
|
+
console.log('Not connected');
|
|
236
|
+
console.log("Run 'simplefin connect' first");
|
|
237
|
+
process.exit(1);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (options.json) {
|
|
241
|
+
console.log(JSON.stringify({
|
|
242
|
+
connected: true,
|
|
243
|
+
server: conn.access_url,
|
|
244
|
+
created_at: conn.created_at,
|
|
245
|
+
}, null, 2));
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
console.log('Connection Status');
|
|
250
|
+
console.log('-----------------');
|
|
251
|
+
console.log('Connected');
|
|
252
|
+
console.log(`Server: ${conn.access_url}`);
|
|
253
|
+
console.log(`Connected since: ${formatDate(new Date(conn.created_at).getTime() / 1000)}`);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
// ===== ACCOUNTS COMMAND =====
|
|
257
|
+
program.command('accounts')
|
|
258
|
+
.description('List all connected accounts')
|
|
259
|
+
.option('--json', 'Output as JSON')
|
|
260
|
+
.option('--balances-only', 'Only show balances, no transactions')
|
|
261
|
+
.action(async (options) => {
|
|
262
|
+
const conn = loadConnection();
|
|
263
|
+
if (!conn) {
|
|
264
|
+
console.log('Not connected');
|
|
265
|
+
process.exit(1);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
try {
|
|
269
|
+
const data = await getAccounts({
|
|
270
|
+
baseUrl: conn.access_url,
|
|
271
|
+
username: conn.username,
|
|
272
|
+
password: conn.password,
|
|
273
|
+
balancesOnly: options.balancesOnly,
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
if (data.errors && data.errors.length > 0) {
|
|
277
|
+
console.log('Errors from server:');
|
|
278
|
+
for (const err of data.errors) {
|
|
279
|
+
console.log(` - ${err}`);
|
|
280
|
+
}
|
|
281
|
+
console.log('');
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const accounts = data.accounts || [];
|
|
285
|
+
|
|
286
|
+
if (options.json) {
|
|
287
|
+
console.log(JSON.stringify({
|
|
288
|
+
connected: true,
|
|
289
|
+
errors: data.errors || [],
|
|
290
|
+
accounts: accounts.map(acc => ({
|
|
291
|
+
id: acc.id,
|
|
292
|
+
name: acc.name,
|
|
293
|
+
organization: acc.org?.name || acc.org?.domain || 'Unknown',
|
|
294
|
+
balance: acc.balance,
|
|
295
|
+
'available-balance': acc['available-balance'],
|
|
296
|
+
currency: acc.currency,
|
|
297
|
+
'balance-date': acc['balance-date'],
|
|
298
|
+
type: acc.type,
|
|
299
|
+
extra: acc.extra,
|
|
300
|
+
})),
|
|
301
|
+
total_accounts: accounts.length,
|
|
302
|
+
}, null, 2));
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
console.log('Accounts');
|
|
307
|
+
console.log('--------');
|
|
308
|
+
for (const acc of accounts) {
|
|
309
|
+
console.log(`${acc.name} (${acc.org?.name || acc.org?.domain || 'Unknown'})`);
|
|
310
|
+
console.log(` Balance: ${acc.balance} ${acc.currency}`);
|
|
311
|
+
if (acc['available-balance'] && acc['available-balance'] !== acc.balance) {
|
|
312
|
+
console.log(` Available: ${acc['available-balance']} ${acc.currency}`);
|
|
313
|
+
}
|
|
314
|
+
console.log(` Last updated: ${formatDate(acc['balance-date'])}`);
|
|
315
|
+
if (acc.type) {
|
|
316
|
+
console.log(` Type: ${acc.type}`);
|
|
317
|
+
}
|
|
318
|
+
if (acc.transactions && acc.transactions.length > 0 && !options.balancesOnly) {
|
|
319
|
+
console.log(` Transactions: ${acc.transactions.length}`);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
console.log('--------');
|
|
323
|
+
console.log(`Total: ${accounts.length} account(s)`);
|
|
324
|
+
} catch (error) {
|
|
325
|
+
console.error('Error:', error.message);
|
|
326
|
+
process.exit(1);
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
// ===== TRANSACTIONS COMMAND =====
|
|
331
|
+
program.command('transactions')
|
|
332
|
+
.description('List transactions')
|
|
333
|
+
.option('-d, --days <days>', 'Number of days to look back', '30')
|
|
334
|
+
.option('--start-date <date>', 'Start date (Unix timestamp or YYYY-MM-DD)')
|
|
335
|
+
.option('--end-date <date>', 'End date (Unix timestamp or YYYY-MM-DD)')
|
|
336
|
+
.option('--account <id>', 'Filter by account ID')
|
|
337
|
+
.option('--pending', 'Include pending transactions')
|
|
338
|
+
.option('--json', 'Output as JSON')
|
|
339
|
+
.action(async (options) => {
|
|
340
|
+
const conn = loadConnection();
|
|
341
|
+
if (!conn) {
|
|
342
|
+
console.log('Not connected');
|
|
343
|
+
process.exit(1);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// Parse dates
|
|
347
|
+
let startDate, endDate;
|
|
348
|
+
|
|
349
|
+
if (options.startDate) {
|
|
350
|
+
if (options.startDate.includes('-')) {
|
|
351
|
+
startDate = Math.floor(new Date(options.startDate).getTime() / 1000);
|
|
352
|
+
} else {
|
|
353
|
+
startDate = parseInt(options.startDate);
|
|
354
|
+
}
|
|
355
|
+
} else {
|
|
356
|
+
const days = parseInt(options.days) || 30;
|
|
357
|
+
startDate = Math.floor(Date.now() / 1000) - (days * 24 * 60 * 60);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
if (options.endDate) {
|
|
361
|
+
if (options.endDate.includes('-')) {
|
|
362
|
+
endDate = Math.floor(new Date(options.endDate).getTime() / 1000);
|
|
363
|
+
} else {
|
|
364
|
+
endDate = parseInt(options.endDate);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
try {
|
|
369
|
+
const data = await getAccounts({
|
|
370
|
+
baseUrl: conn.access_url,
|
|
371
|
+
username: conn.username,
|
|
372
|
+
password: conn.password,
|
|
373
|
+
startDate: startDate.toString(),
|
|
374
|
+
endDate: endDate?.toString(),
|
|
375
|
+
account: options.account,
|
|
376
|
+
pending: options.pending,
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
if (data.errors && data.errors.length > 0) {
|
|
380
|
+
console.log('Errors from server:');
|
|
381
|
+
for (const err of data.errors) {
|
|
382
|
+
console.log(` - ${err}`);
|
|
383
|
+
}
|
|
384
|
+
console.log('');
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
const accounts = data.accounts || [];
|
|
388
|
+
const allTransactions = [];
|
|
389
|
+
|
|
390
|
+
for (const acc of accounts) {
|
|
391
|
+
for (const tx of acc.transactions || []) {
|
|
392
|
+
allTransactions.push({
|
|
393
|
+
...tx,
|
|
394
|
+
account_name: acc.name,
|
|
395
|
+
account_id: acc.id,
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
allTransactions.sort((a, b) => b.posted - a.posted);
|
|
401
|
+
|
|
402
|
+
if (options.json) {
|
|
403
|
+
console.log(JSON.stringify({
|
|
404
|
+
connected: true,
|
|
405
|
+
errors: data.errors || [],
|
|
406
|
+
query: {
|
|
407
|
+
start_date: startDate,
|
|
408
|
+
end_date: endDate,
|
|
409
|
+
account: options.account,
|
|
410
|
+
pending: options.pending,
|
|
411
|
+
},
|
|
412
|
+
transactions: allTransactions,
|
|
413
|
+
count: allTransactions.length,
|
|
414
|
+
}, null, 2));
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
console.log('Transactions');
|
|
419
|
+
console.log('------------');
|
|
420
|
+
|
|
421
|
+
if (startDate && !options.startDate) {
|
|
422
|
+
const days = parseInt(options.days) || 30;
|
|
423
|
+
console.log(`From last ${days} days`);
|
|
424
|
+
} else if (startDate) {
|
|
425
|
+
console.log(`From ${formatDate(startDate)}`);
|
|
426
|
+
if (endDate) console.log(`To ${formatDate(endDate)}`);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
console.log(`Found ${allTransactions.length} transaction(s)\n`);
|
|
430
|
+
|
|
431
|
+
for (const tx of allTransactions) {
|
|
432
|
+
const amount = parseFloat(tx.amount).toFixed(2);
|
|
433
|
+
const sign = tx.amount.startsWith('-') ? '' : '+';
|
|
434
|
+
const pending = tx.pending ? '[PENDING] ' : '';
|
|
435
|
+
const date = tx.posted ? formatDateFull(tx.posted) : 'N/A';
|
|
436
|
+
|
|
437
|
+
console.log(`${date}`);
|
|
438
|
+
console.log(` ${sign}${amount.padStart(10)} ${pending}${truncate(tx.description, 50)}`);
|
|
439
|
+
console.log(` Account: ${tx.account_name}`);
|
|
440
|
+
if (tx.transacted_at && tx.transacted_at !== tx.posted) {
|
|
441
|
+
console.log(` Transacted: ${formatDateFull(tx.transacted_at)}`);
|
|
442
|
+
}
|
|
443
|
+
if (tx.category || (tx.extra && tx.extra.category)) {
|
|
444
|
+
console.log(` Category: ${tx.category || tx.extra.category}`);
|
|
445
|
+
}
|
|
446
|
+
console.log('');
|
|
447
|
+
}
|
|
448
|
+
} catch (error) {
|
|
449
|
+
console.error('Error:', error.message);
|
|
450
|
+
process.exit(1);
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
program.parse();
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dilllxd/simplefin-cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "CLI tool for accessing financial data via SimpleFIN Bridge",
|
|
5
|
+
"author": "dilllxd",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://git.dylan.lol/dylan/cli-tools"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://git.dylan.lol/dylan/cli-tools/issues"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://git.dylan.lol/dylan/cli-tools/tree/main/simplefin-cli",
|
|
15
|
+
"keywords": [
|
|
16
|
+
"simplefin",
|
|
17
|
+
"finance",
|
|
18
|
+
"bank",
|
|
19
|
+
"cli",
|
|
20
|
+
"terminal"
|
|
21
|
+
],
|
|
22
|
+
"bin": {
|
|
23
|
+
"simplefin": "./bin/simplefin.js"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"bin/",
|
|
27
|
+
"LICENSE"
|
|
28
|
+
],
|
|
29
|
+
"os": [
|
|
30
|
+
"linux",
|
|
31
|
+
"darwin",
|
|
32
|
+
"win32"
|
|
33
|
+
],
|
|
34
|
+
"cpu": [
|
|
35
|
+
"x64",
|
|
36
|
+
"x86",
|
|
37
|
+
"arm64",
|
|
38
|
+
"armv7l"
|
|
39
|
+
],
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"axios": "1.6.0",
|
|
42
|
+
"commander": "11.0.0"
|
|
43
|
+
},
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": ">=18.0.0"
|
|
46
|
+
}
|
|
47
|
+
}
|