Skip to content
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

Include additionalInformation in notes #1490

Conversation

CharlieMK
Copy link

Implements #1466
Nothing changes for users who use a bank that does not use the additionalInformation field. For banks that do, the remittanceInformation is combined with the information from the atmPosName and narrative subfields of the additionalInformation field.

@netlify
Copy link

netlify bot commented Aug 8, 2023

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit e04fe48
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/64d250dfbcb2940008227614
😎 Deploy Preview https://deploy-preview-1490.demo.actualbudget.org/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 8, 2023

Bundle Stats — desktop-client

Hey 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

Files count Total bundle size % Changed
14 2.12 MB 0%
Changeset
File Δ Size
../loot-core/src/shared/util.ts 📈 +659 B (+9.75%) 6.6 kB → 7.25 kB
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

No assets were bigger

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
static/js/main.js 944.09 kB 0%
static/js/171.chunk.js 396.24 kB 0%
static/media/Inter-italic.var.woff2 239.29 kB 0%
static/media/Inter-roman.var.woff2 221.86 kB 0%
static/js/wide-components.chunk.js 156.68 kB 0%
static/js/383.chunk.js 117.35 kB 0%
static/js/reports.chunk.js 40.96 kB 0%
static/js/narrow-components.chunk.js 24.62 kB 0%
static/js/969.chunk.js 12.94 kB 0%
static/js/resize-observer-polyfill.chunk.js 8.12 kB 0%
static/css/main.css 5.82 kB 0%
asset-manifest.json 1.78 kB 0%
index.html 1.66 kB 0%
static/media/browser-server.js 963 B 0%

@github-actions
Copy link
Contributor

github-actions bot commented Aug 8, 2023

Bundle Stats — loot-core

Hey 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

Files count Total bundle size % Changed
2 1.97 MB → 1.97 MB (+406 B) +0.02%
Changeset
File Δ Size
packages/loot-core/src/shared/util.ts 📈 +820 B (+10.01%) 8 kB → 8.8 kB
packages/loot-core/src/server/accounts/sync.ts 📈 +560 B (+2.09%) 26.22 kB → 26.77 kB
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

Asset File Size % Changed
kcab.worker.js 1012.13 kB → 1012.53 kB (+406 B) +0.04%

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
xfo.xfo.kcab.worker.js 1004.04 kB 0%

Copy link
Member

@MatissJanis MatissJanis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋

The additionalInformation field is localized to each bank. There is no standard for what we get in this field. For example: my bank just returns an ID of some sort in this field.

Instead of applying a patch in the UI - what you can do is create a custom mapper for your specific bank in the server. Here's an example how it can be done: actualbudget/actual-server#239

@trafico-bot trafico-bot bot added ⚠️ Changes requested Pull Request needs changes before it can be reviewed again and removed 🔍 Ready for Review labels Aug 8, 2023
@CharlieMK
Copy link
Author

👋

The additionalInformation field is localized to each bank. There is no standard for what we get in this field. For example: my bank just returns an ID of some sort in this field.

Instead of applying a patch in the UI - what you can do is create a custom mapper for your specific bank in the server. Here's an example how it can be done: actualbudget/actual-server#239

Hi, thanks for the review.
This may indeed be a better idea. I think I can get started, but I'm not quite sure what the default mapper is: the integration-bank.js? I only want to override the transaction formatting, not the account or balance calculation.

@MatissJanis
Copy link
Member

Hi, thanks for the review.
This may indeed be a better idea. I think I can get started, but I'm not quite sure what the default mapper is: the integration-bank.js? I only want to override the transaction formatting, not the account or balance calculation.

Don't build it in the default bank integration as the additionalInformation does not have a common format among the banks. Your custom logic should go in a custom bank mapper. Specific to the bank you are using. The linked PR has an example of how a custom mapper would look like: https://github.com/actualbudget/actual-server/blob/c78bb084de618e89256db17d1114f290b0de73f6/src/app-gocardless/banks/american-express-aesudef1.js

The existing mappers are here: https://github.com/actualbudget/actual-server/tree/c78bb084de618e89256db17d1114f290b0de73f6/src/app-gocardless/banks

Comment on lines +366 to +390
export function looselyParseAdditionalInformation(additionalInformation) {
let additionalInformationJson;
try {
additionalInformationJson = JSON.parse(additionalInformation);
} catch (e) {
try {
// It was not valid JSON, attempt to make the payload valid JSON using regex.
let result = {};
let matches = additionalInformation.matchAll(
/(, )?([^:]+): ((\[.*?\])|([^,]*))/g,
);
for (let match of matches) {
let key = match[2].trim();
let value = (match[4] || match[5]).trim();
// Remove square brackets and single quotes and commas
value = value.replace(/[[\]',]/g, '');
result[key] = value;
}
additionalInformationJson = result;
} catch (e) {
additionalInformationJson = {};
}
}
return additionalInformationJson;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of things:

  1. I've never heard of a single case in which this field would contain serialized JSON, so trying to parse it as JSON seems pointless to me.
  2. I'm not really a fan of using regex to try to parse something like this, especially without a specification of the actual format used that we can validate it against. Your current regexes would break if e.g. one of the fields can contain ], which without a specification we don't know if it's valid.

@kyrias
Copy link
Contributor

kyrias commented Aug 8, 2023

Instead of applying a patch in the UI - what you can do is create a custom mapper for your specific bank in the server. Here's an example how it can be done: actualbudget/actual-server#239

Though to be clear, to do that kind of mapping you need the normalization of transaction commit that's currently in both of my bank integration PRs, so to start working on it you'll need to base it off of one of those two branches.

@CharlieMK
Copy link
Author

Instead of applying a patch in the UI - what you can do is create a custom mapper for your specific bank in the server. Here's an example how it can be done: actualbudget/actual-server#239

Though to be clear, to do that kind of mapping you need the normalization of transaction commit that's currently in both of my bank integration PRs, so to start working on it you'll need to base it off of one of those two branches.

Ok, the normalizetransaction makes sense. I'll start from actualbudget/actual-server#237.

Regarding your review: I assumed some banks would return JSON, but as I will now try to switch to a custom bank mapper, that argument is irrelevant. Then again, what alternatives would you recommend to parsing it with regex?

@CharlieMK
Copy link
Author

CharlieMK commented Aug 9, 2023

Ok, I propose to close this pull request in favor of actualbudget/actual-server#242
No changes in actual required, all changes are now handled in actual-server.

@MatissJanis
Copy link
Member

Thanks @CharlieMK !

@MatissJanis MatissJanis closed this Aug 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚠️ Changes requested Pull Request needs changes before it can be reviewed again
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants