@actual-app/api 1.1.3 → 2.0.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/app/bundle.api.js +69607 -0
- package/app/bundle.api.js.map +1 -0
- package/{query.js → app/query.js} +24 -1
- package/default-db.sqlite +0 -0
- package/index.js +10 -0
- package/injected.js +5 -0
- package/local.js +28 -0
- package/{api.js → methods.js} +18 -15
- package/migrations/.force-copy-windows +0 -0
- package/migrations/1548957970627_remove-db-version.sql +5 -0
- package/migrations/1550601598648_payees.sql +23 -0
- package/migrations/1555786194328_remove_category_group_unique.sql +25 -0
- package/migrations/1561751833510_indexes.sql +7 -0
- package/migrations/1567699552727_budget.sql +38 -0
- package/migrations/1582384163573_cleared.sql +6 -0
- package/migrations/1597756566448_rules.sql +10 -0
- package/migrations/1608652596043_parent_field.sql +13 -0
- package/migrations/1608652596044_trans_views.sql +56 -0
- package/migrations/1612625548236_optimize.sql +7 -0
- package/migrations/1614782639336_trans_views2.sql +33 -0
- package/migrations/1615745967948_meta.sql +10 -0
- package/migrations/1616167010796_accounts_order.sql +5 -0
- package/migrations/1618975177358_schedules.sql +28 -0
- package/migrations/1632571489012_remove_cache.js +135 -0
- package/package.json +4 -3
- package/test.js +8 -0
- package/connection.js +0 -118
- package/get-socket.js +0 -39
package/connection.js
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
let ipc = require('node-ipc');
|
|
2
|
-
let uuid = require('uuid');
|
|
3
|
-
let getSocket = require('./get-socket');
|
|
4
|
-
|
|
5
|
-
process.traceProcessWarnings = true;
|
|
6
|
-
ipc.config.silent = true;
|
|
7
|
-
let socketClient = null;
|
|
8
|
-
let replyHandlers = new Map();
|
|
9
|
-
let initialized = null;
|
|
10
|
-
|
|
11
|
-
process.on('unhandledRejection', function(error, promise) {
|
|
12
|
-
console.log(error);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
function send(name, args) {
|
|
16
|
-
return new Promise((resolve, reject) => {
|
|
17
|
-
let id = uuid.v4();
|
|
18
|
-
replyHandlers.set(id, { resolve, reject });
|
|
19
|
-
if (socketClient) {
|
|
20
|
-
socketClient.emit('message', JSON.stringify({ id, name, args }));
|
|
21
|
-
}
|
|
22
|
-
}).catch(err => {
|
|
23
|
-
if (typeof err === 'string' && err.includes('API Error')) {
|
|
24
|
-
// Throwing the error here captures the correct async stack trace.
|
|
25
|
-
// If we just let the promise reject
|
|
26
|
-
throw new Error(err);
|
|
27
|
-
}
|
|
28
|
-
throw err;
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async function init(socketName) {
|
|
33
|
-
// Support calling this multiple times before it actually connects
|
|
34
|
-
if (initialized) {
|
|
35
|
-
return initialized;
|
|
36
|
-
}
|
|
37
|
-
initialized = getSocket(socketName);
|
|
38
|
-
socketClient = await initialized;
|
|
39
|
-
|
|
40
|
-
if (!socketClient) {
|
|
41
|
-
// TODO: This could spawn Actual automatically. The ideal solution
|
|
42
|
-
// would be to bundle the entire backend and embed it directly
|
|
43
|
-
// into the distributed library.
|
|
44
|
-
throw new Error("Couldn't connect to Actual. Please run the app first.");
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
socketClient.on('message', data => {
|
|
48
|
-
const msg = JSON.parse(data);
|
|
49
|
-
|
|
50
|
-
if (msg.type === 'error') {
|
|
51
|
-
// The API should not be getting this message type anymore.
|
|
52
|
-
// Errors are propagated through the `reply` message which gives
|
|
53
|
-
// more context for which call made the error. Just in case,
|
|
54
|
-
// keep this code here for now.
|
|
55
|
-
const { id } = msg;
|
|
56
|
-
replyHandlers.delete(id);
|
|
57
|
-
} else if (msg.type === 'reply') {
|
|
58
|
-
const { id, error, result } = msg;
|
|
59
|
-
|
|
60
|
-
const handler = replyHandlers.get(id);
|
|
61
|
-
if (handler) {
|
|
62
|
-
replyHandlers.delete(id);
|
|
63
|
-
|
|
64
|
-
if (error) {
|
|
65
|
-
handler.reject('[API Error] ' + error.message);
|
|
66
|
-
} else {
|
|
67
|
-
handler.resolve(result);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
} else if (msg.type === 'push') {
|
|
71
|
-
// Do nothing
|
|
72
|
-
} else {
|
|
73
|
-
throw new Error('Unknown message type: ' + JSON.stringify(msg));
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function disconnect() {
|
|
79
|
-
if (socketClient) {
|
|
80
|
-
ipc.disconnect(socketClient.id);
|
|
81
|
-
socketClient = null;
|
|
82
|
-
initialized = false;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
async function _run(func) {
|
|
87
|
-
let res;
|
|
88
|
-
|
|
89
|
-
try {
|
|
90
|
-
await init();
|
|
91
|
-
res = await func();
|
|
92
|
-
} catch (e) {
|
|
93
|
-
send('api/cleanup', { hasError: true });
|
|
94
|
-
disconnect();
|
|
95
|
-
throw e;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
send('api/cleanup');
|
|
99
|
-
disconnect();
|
|
100
|
-
return res;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
async function runWithBudget(id, func) {
|
|
104
|
-
return _run(async () => {
|
|
105
|
-
await send('api/load-budget', { id });
|
|
106
|
-
return func();
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
async function runImport(name, func) {
|
|
111
|
-
return _run(async () => {
|
|
112
|
-
await send('api/start-import', { budgetName: name });
|
|
113
|
-
await func();
|
|
114
|
-
await send('api/finish-import');
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
module.exports = { init, send, disconnect, runWithBudget, runImport };
|
package/get-socket.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
const net = require('net');
|
|
2
|
-
const os = require('os');
|
|
3
|
-
const { join } = require('path');
|
|
4
|
-
const ipc = require('node-ipc');
|
|
5
|
-
|
|
6
|
-
function connect(name) {
|
|
7
|
-
return new Promise((resolve, reject) => {
|
|
8
|
-
ipc.connectTo(name, () => {
|
|
9
|
-
ipc.of[name].on('error', () => {
|
|
10
|
-
ipc.disconnect(name);
|
|
11
|
-
resolve(false);
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
ipc.of[name].on('connect', () => {
|
|
15
|
-
resolve(ipc.of[name]);
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
async function getSocket(name) {
|
|
22
|
-
if (name) {
|
|
23
|
-
return connect(name);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
let currentSocket = 1;
|
|
27
|
-
let client = null;
|
|
28
|
-
while (!(client = await connect('actual' + currentSocket))) {
|
|
29
|
-
currentSocket++;
|
|
30
|
-
|
|
31
|
-
if (currentSocket >= 10) {
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return client;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
module.exports = getSocket;
|