-
Notifications
You must be signed in to change notification settings - Fork 1
/
actual.js
61 lines (54 loc) · 1.44 KB
/
actual.js
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
const { getAppConfigFromEnv } = require("./config");
const actual = require("@actual-app/api");
const fs = require("fs");
const appConfig = getAppConfigFromEnv();
/**
*
* @returns {Promise<typeof actual>}
*/
async function initialize(config) {
try {
const tmp_dir = `./temp_data_actual/${config.get("user")}`
fs.mkdirSync(tmp_dir, { recursive: true });
await actual.init({
serverURL: appConfig.ACTUAL_SERVER_URL,
password: appConfig.ACTUAL_SERVER_PASSWORD,
dataDir: tmp_dir
});
let id = config.get("budget_id")
await actual.downloadBudget(id);
} catch (e) {
throw new Error(`Actual Budget Error: ${e.message}`);
}
return actual;
}
/**
*
* @param {typeof actual} actualInstance
*/
function listAccounts(actualInstance) {
return actualInstance.getAccounts();
}
async function importTransactions(actualInstance, accountId, transactions) {
console.info("Importing transactions raw data START:")
console.debug(transactions)
const actualResult = await actualInstance.importTransactions(
accountId,
transactions
);
console.info("Actual logs: ", actualResult);
}
/**
*
* @param {typeof actual} actualInstance
*/
async function finalize(actualInstance) {
await actualInstance.sync()
await actualInstance.shutdown();
}
module.exports = {
initialize,
listAccounts,
importTransactions,
finalize
}