From b08b473c1f8af0c22b3379cccf1f17aecd9b538c Mon Sep 17 00:00:00 2001 From: Joel Jeremy Marquez Date: Fri, 17 Nov 2023 08:12:19 -0800 Subject: [PATCH 1/3] Support multiple months in experimental ofx parser --- .../loot-core/src/server/accounts/ofx2json.ts | 65 ++++++++++--------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/packages/loot-core/src/server/accounts/ofx2json.ts b/packages/loot-core/src/server/accounts/ofx2json.ts index ad43b099ef1..8f1224be775 100644 --- a/packages/loot-core/src/server/accounts/ofx2json.ts +++ b/packages/loot-core/src/server/accounts/ofx2json.ts @@ -44,48 +44,49 @@ function getStmtTrn(data) { } function getBankStmtTrn(ofx) { - const msg = ofx?.['BANKMSGSRSV1']; - const stmtTrnRs = msg?.['STMTTRNRS']; - const stmtRs = stmtTrnRs?.['STMTRS']; - const tranList = stmtRs?.['BANKTRANLIST']; - // Could be an array or a single object. + // Somes values could be an array or a single object. // xml2js serializes single item to an object and multiple to an array. - const stmtTrn = tranList?.['STMTTRN']; - - if (!Array.isArray(stmtTrn)) { - return [stmtTrn]; - } - return stmtTrn; + const msg = ofx?.['BANKMSGSRSV1']; + const stmtTrnRs = getAsArray(msg?.['STMTTRNRS']); + const result = stmtTrnRs.flatMap(s => { + const stmtRs = s?.['STMTRS']; + const tranList = stmtRs?.['BANKTRANLIST']; + const stmtTrn = tranList?.['STMTTRN']; + return getAsArray(stmtTrn); + }); + return result; } function getCcStmtTrn(ofx) { - const msg = ofx?.['CREDITCARDMSGSRSV1']; - const stmtTrnRs = msg?.['CCSTMTTRNRS']; - const stmtRs = stmtTrnRs?.['CCSTMTRS']; - const tranList = stmtRs?.['BANKTRANLIST']; - // Could be an array or a single object. + // Some values could be an array or a single object. // xml2js serializes single item to an object and multiple to an array. - const stmtTrn = tranList?.['STMTTRN']; - - if (!Array.isArray(stmtTrn)) { - return [stmtTrn]; - } - return stmtTrn; + const msg = ofx?.['CREDITCARDMSGSRSV1']; + const stmtTrnRs = getAsArray(msg?.['CCSTMTTRNRS']); + const result = stmtTrnRs.flatMap(s => { + const stmtRs = s?.['CCSTMTRS']; + const tranList = stmtRs?.['BANKTRANLIST']; + const stmtTrn = tranList?.['STMTTRN']; + return getAsArray(stmtTrn); + }); + return result; } function getInvStmtTrn(ofx) { - const msg = ofx?.['INVSTMTMSGSRSV1']; - const stmtTrnRs = msg?.['INVSTMTTRNRS']; - const stmtRs = stmtTrnRs?.['INVSTMTRS']; - const tranList = stmtRs?.['INVTRANLIST']; - // Could be an array or a single object. + // Somes values could be an array or a single object. // xml2js serializes single item to an object and multiple to an array. - const stmtTrn = tranList?.['INVBANKTRAN']?.flatMap(t => t?.['STMTTRN']); + const msg = ofx?.['INVSTMTMSGSRSV1']; + const stmtTrnRs = getAsArray(msg?.['INVSTMTTRNRS']); + const result = stmtTrnRs.flatMap(s => { + const stmtRs = s?.['INVSTMTRS'] + const tranList = stmtRs?.['INVTRANLIST']; + const stmtTrn = tranList?.['INVBANKTRAN']?.flatMap(t => t?.['STMTTRN']); + return getAsArray(stmtTrn); + }); + return result; +} - if (!Array.isArray(stmtTrn)) { - return [stmtTrn]; - } - return stmtTrn; +function getAsArray(value) { + return Array.isArray(value) ? value : [value]; } function mapOfxTransaction(stmtTrn): OFXTransaction { From 4849f0baf80afc8f8cdd02da80fc1f628fe82a3a Mon Sep 17 00:00:00 2001 From: Joel Jeremy Marquez Date: Fri, 17 Nov 2023 08:13:20 -0800 Subject: [PATCH 2/3] Release notes --- upcoming-release-notes/1921.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 upcoming-release-notes/1921.md diff --git a/upcoming-release-notes/1921.md b/upcoming-release-notes/1921.md new file mode 100644 index 00000000000..71301393b26 --- /dev/null +++ b/upcoming-release-notes/1921.md @@ -0,0 +1,6 @@ +--- +category: Bugfix +authors: [joel-jeremy] +--- + +Experimental ofx parser: Support multiple months in ofx file From 2b1a364ba145b59680aa429529eca9d290947548 Mon Sep 17 00:00:00 2001 From: Joel Jeremy Marquez Date: Fri, 17 Nov 2023 08:25:00 -0800 Subject: [PATCH 3/3] Fix lint error --- packages/loot-core/src/server/accounts/ofx2json.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/loot-core/src/server/accounts/ofx2json.ts b/packages/loot-core/src/server/accounts/ofx2json.ts index 8f1224be775..4b6d435c6c8 100644 --- a/packages/loot-core/src/server/accounts/ofx2json.ts +++ b/packages/loot-core/src/server/accounts/ofx2json.ts @@ -77,7 +77,7 @@ function getInvStmtTrn(ofx) { const msg = ofx?.['INVSTMTMSGSRSV1']; const stmtTrnRs = getAsArray(msg?.['INVSTMTTRNRS']); const result = stmtTrnRs.flatMap(s => { - const stmtRs = s?.['INVSTMTRS'] + const stmtRs = s?.['INVSTMTRS']; const tranList = stmtRs?.['INVTRANLIST']; const stmtTrn = tranList?.['INVBANKTRAN']?.flatMap(t => t?.['STMTTRN']); return getAsArray(stmtTrn);