New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨ (api) ability to run bank sync via the API #2683
Conversation
✅ Deploy Preview for actualbudget ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Bundle Stats — desktop-clientHey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle. As this PR is updated, I'll keep you updated on how the bundle size is impacted. Total
Changeset
View detailed bundle breakdownAdded No assets were added Removed No assets were removed Bigger No assets were bigger Smaller
Unchanged
|
Bundle Stats — loot-coreHey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle. As this PR is updated, I'll keep you updated on how the bundle size is impacted. Total
Changeset
View detailed bundle breakdownAdded No assets were added Removed No assets were removed Bigger
Smaller No assets were smaller Unchanged No assets were unchanged |
When calling /data/home/matt/cron/actual/node_modules/@actual-app/api/dist/app/bundle.api.js:43402
handlers['accounts-bank-sync'] = async function ({ id }) {
^
TypeError: Cannot destructure property 'id' of 'undefined' as it is undefined.
at handlers.accounts-bank-sync (/data/home/matt/cron/actual/node_modules/@actual-app/api/dist/app/bundle.api.js:43402:64)
at handlers.api/bank-sync (/data/home/matt/cron/actual/node_modules/@actual-app/api/dist/app/bundle.api.js:34823:72)
at runHandler (/data/home/matt/cron/actual/node_modules/@actual-app/api/dist/app/bundle.api.js:44781:33)
at Object.send (/data/home/matt/cron/actual/node_modules/@actual-app/api/dist/app/bundle.api.js:44463:94)
at send (/data/home/matt/cron/actual/node_modules/@actual-app/api/dist/methods.js:31:21)
at Object.runBankSync (/data/home/matt/cron/actual/node_modules/@actual-app/api/dist/methods.js:58:12)
at /data/home/matt/cron/actual/bankSync.js:25:12
Node.js v18.19.1 |
Thanks for testing @matt-fidd ! I must have accidentally removed something when I cleaned up the implementation. Should be patched now. Give it another go. |
Thanks @MatissJanis! Looks better now! It appears to hit a problem halfway through my sync where it tries to re sync with the server in the middle of polling gocardless and falls over. Bank Sync operation for account: ########
Pulling transactions from GoCardless
Syncing since 2024-05-01T17:10:28.143Z-0000-b80ed5e91c4802ff 7 (attempt: 0)
SyncError: SyncError: encrypt-failure
at Module.encode (/data/home/matt/cron/actual/node_modules/@actual-app/api/dist/app/bundle.api.js:47024:35)
at _fullSync (/data/home/matt/cron/actual/node_modules/@actual-app/api/dist/app/bundle.api.js:47705:77)
at async /data/home/matt/cron/actual/node_modules/@actual-app/api/dist/app/bundle.api.js:47611:32 {
reason: 'encrypt-failure',
meta: { isMissingKey: true }
} From then on, any API interactions are met with the below error. node bankSync.js
- Connecting
-- Success
- Downloading
Loaded spreadsheet from cache (3136 items)
Syncing since 2024-05-01T17:10:28.143Z-0000-b80ed5e91c4802ff 7 (attempt: 0)
SyncError: SyncError: encrypt-failure
at Module.encode (/data/home/matt/cron/actual/node_modules/@actual-app/api/dist/app/bundle.api.js:47024:35)
at _fullSync (/data/home/matt/cron/actual/node_modules/@actual-app/api/dist/app/bundle.api.js:47705:77)
at async /data/home/matt/cron/actual/node_modules/@actual-app/api/dist/app/bundle.api.js:47611:32
at async initialFullSync (/data/home/matt/cron/actual/node_modules/@actual-app/api/dist/app/bundle.api.js:47597:32)
at async handlers.sync-budget (/data/home/matt/cron/actual/node_modules/@actual-app/api/dist/app/bundle.api.js:43980:32)
at async handlers.api/download-budget (/data/home/matt/cron/actual/node_modules/@actual-app/api/dist/app/bundle.api.js:34777:36) {
reason: 'encrypt-failure',
meta: { isMissingKey: true }
}
/data/home/matt/cron/actual/node_modules/@actual-app/api/dist/app/bundle.api.js:34779
throw new Error((0, _shared_errors__WEBPACK_IMPORTED_MODULE_2__.getSyncError)(result.error, localBudget.id));
^
Error: We had an unknown problem opening ?My-Finances-5cca4be?.
at handlers.api/download-budget (/data/home/matt/cron/actual/node_modules/@actual-app/api/dist/app/bundle.api.js:34779:31)
Node.js v18.19.1 and to be able to continue, I have to wipe the cache directory and resync from blank |
Some debugging later, the error is thrown here as the With the debug lines below added export function getKey(keyId) {
if (keyId == null || keys[keyId] == null) {
+ console.log(keyId);
+ console.log(keys);
+ console.log(keys[keyId]);
throw new Error('missing-key');
}
return keys[keyId];
} The following is printed (master key has been redacted but it is set!) Loaded spreadsheet from cache (3136 items)
Syncing since 2024-05-01T21:31:22.845Z-0073-9f76373186bb94dd 13 (attempt: 0)
***REDACTED KEY***
{}
undefined
SyncError: SyncError: encrypt-failure
... |
Looks like the e2e encryption is having problems there for you. Did you set the encryption password in the code? https://actualbudget.org/docs/api/#connecting-to-a-remote-server
|
I did set the encryption password and it manages to connect and sync a couple of accounts, and then it gets caught up somewhere and empties the keys object in /loot-core/src/server/encryption.ts. I've checked and neither the |
Done some more digging, I can't force it to happen with any other API functions. If I just sync one bank account over and over it also does not happen, only when calling |
Thanks for the investigation @matt-fidd . I've split off the patch of this issue into a separate PR: #2698 |
Amazing, thank you @MatissJanis! |
@MatissJanis Is there much more that needs added here or is the ready for review? |
Out for review again. Would appreciate another round of testing from you @matt-fidd ! 🙇 |
All looking good!! |
Allow running 3rd party (gocardless, simplefin) bank-sync via the API package.
This will allow people to run the bank-sync operation in the background on a schedule (i.e. with cron jobs).
Usage:
Docs: actualbudget/docs#350