ofx-data-extractor 1.4.3 → 1.4.5

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.
@@ -0,0 +1,88 @@
1
+ import type { ConfigDate, ConfigFitId, DateResponse, MetaData } from './common';
2
+ export type Status = {
3
+ CODE: string;
4
+ SEVERITY: 'INFO' | 'WARN' | 'ERROR';
5
+ MESSAGE?: string;
6
+ };
7
+ export type BankAccountFrom = {
8
+ BANKID: string;
9
+ ACCTID: string;
10
+ ACCTTYPE: 'CHECKING' | 'SAVINGS' | 'CREDITLINE' | 'MONEYMRKT';
11
+ };
12
+ export type TransactionType = 'CREDIT' | 'DEBIT' | 'INT' | 'DIV' | 'FEE' | 'SRVCHG' | 'DEP' | 'ATM' | 'POS' | 'XFER' | 'CHECK' | 'PAYMENT' | 'CASH' | 'DIRECTDEP' | 'DIRECTDEBIT' | 'REPEATPMT' | 'OTHER';
13
+ export type OfxConfig = ConfigDate & {
14
+ fitId?: ConfigFitId;
15
+ nativeTypes?: boolean;
16
+ };
17
+ export type STRTTRN = {
18
+ TRNTYPE: TransactionType;
19
+ DTPOSTED: DateResponse;
20
+ TRNAMT: string;
21
+ FITID: string | {
22
+ date: string;
23
+ protocol: string;
24
+ transactionCode: string;
25
+ };
26
+ CHECKNUM?: string;
27
+ MEMO?: string;
28
+ DTAVAIL?: string;
29
+ };
30
+ export type BankTransferList = {
31
+ DTSTART: DateResponse;
32
+ DTEND: DateResponse;
33
+ STRTTRN: STRTTRN[];
34
+ };
35
+ export type Balance = {
36
+ BALAMT: string;
37
+ DTASOF: DateResponse;
38
+ };
39
+ export type FINANCIAL_INSTITUTION = {
40
+ ORG: string;
41
+ FID: string;
42
+ };
43
+ export type StatementResponse = {
44
+ CURDEF: string;
45
+ BANKACCTFROM: BankAccountFrom;
46
+ BANKTRANLIST: BankTransferList;
47
+ LEDGERBAL: Balance;
48
+ AVAILBAL?: Balance;
49
+ MKTGINFO?: string;
50
+ };
51
+ export type Bank = {
52
+ STMTTRNRS: {
53
+ TRNUID: number;
54
+ STATUS: Status;
55
+ STMTRS: StatementResponse;
56
+ };
57
+ };
58
+ export type CreditCard = {
59
+ CCSTMTTRNRS: {
60
+ TRNUID: number;
61
+ STATUS: Status;
62
+ CCSTMTRS: {
63
+ CURDEF: string;
64
+ CCACCTFROM: {
65
+ ACCTID: string;
66
+ };
67
+ BANKTRANLIST: BankTransferList;
68
+ LEDGERBAL: Balance;
69
+ MKTGINFO: string;
70
+ };
71
+ };
72
+ };
73
+ export type OfxStructure = {
74
+ OFX: {
75
+ SIGNONMSGSRSV1: {
76
+ SONRS: {
77
+ STATUS: Status;
78
+ DTSERVER: DateResponse;
79
+ LANGUAGE: string;
80
+ DTACCTUP: DateResponse;
81
+ FI: FINANCIAL_INSTITUTION;
82
+ };
83
+ };
84
+ BANKMSGSRSV1: Bank;
85
+ CREDITCARDMSGSRSV1: CreditCard;
86
+ };
87
+ };
88
+ export type OfxResponse = MetaData & OfxStructure;
@@ -0,0 +1,27 @@
1
+ import { AccountType, Balance, StatementTransaction, Status } from './common';
2
+ export interface BankResponse {
3
+ STMTTRNRS: StatementTransactionResponse;
4
+ }
5
+ export interface StatementTransactionResponse {
6
+ TRNUID: string;
7
+ STATUS: Status;
8
+ STMTRS: StatementResponse;
9
+ }
10
+ export interface StatementResponse {
11
+ CURDEF: string;
12
+ BANKACCTFROM: BankAccount;
13
+ BANKTRANLIST: BankTransactionList;
14
+ LEDGERBAL: Balance;
15
+ AVAILBAL?: Balance;
16
+ }
17
+ export type BankAccount = {
18
+ BANKID: string;
19
+ ACCTID: string;
20
+ ACCTTYPE: AccountType;
21
+ };
22
+ export type BankTransactionList = {
23
+ DTSTART: string;
24
+ DTEND: string;
25
+ STMTTRN: StatementTransaction[];
26
+ STRTTRN: StatementTransaction[];
27
+ };
@@ -0,0 +1,25 @@
1
+ export interface Status {
2
+ CODE: number | string;
3
+ SEVERITY: 'INFO' | 'WARN' | 'ERROR';
4
+ MESSAGE?: string;
5
+ }
6
+ export type AccountType = 'CHECKING' | 'SAVINGS' | 'CREDITLINE' | 'MONEYMRKT';
7
+ export type BankAccount = {
8
+ BANKID: string;
9
+ ACCTID: string;
10
+ ACCTTYPE: AccountType;
11
+ };
12
+ export type TransactionType = 'CREDIT' | 'DEBIT' | 'INT' | 'DIV' | 'FEE' | 'SRVCHG' | 'DEP' | 'ATM' | 'POS' | 'XFER' | 'CHECK' | 'PAYMENT' | 'CASH' | 'DIRECTDEP' | 'DIRECTDEBIT' | 'REPEATPMT' | 'OTHER';
13
+ export interface Balance {
14
+ BALAMT: number;
15
+ DTASOF: string;
16
+ }
17
+ export type StatementTransaction = {
18
+ TRNTYPE: TransactionType;
19
+ DTPOSTED: string;
20
+ DTAVAIL?: string;
21
+ TRNAMT: number;
22
+ FITID: string;
23
+ CHECKNUM?: string;
24
+ MEMO?: string;
25
+ };
@@ -0,0 +1,20 @@
1
+ import { BankTransactionList } from './banking';
2
+ import { Balance, Status } from './common';
3
+ export type CreditCardTransactionResponse = {
4
+ TRNUID: string;
5
+ STATUS: Status;
6
+ CCSTMTRS: CreditCardStatementResponse;
7
+ };
8
+ export type CreditCardStatementResponse = {
9
+ CURDEF: string;
10
+ CCACCTFROM: CreditCardAccount;
11
+ BANKTRANLIST: BankTransactionList;
12
+ LEDGERBAL: Balance;
13
+ AVAILBAL?: Balance;
14
+ };
15
+ export type CreditCardAccount = {
16
+ ACCTID: string;
17
+ };
18
+ export type CreditCardResponse = {
19
+ CCSTMTTRNRS: CreditCardTransactionResponse;
20
+ };
@@ -0,0 +1,13 @@
1
+ import { MetaData } from '../common';
2
+ import { BankResponse } from './banking';
3
+ import { CreditCardResponse } from './credit-card';
4
+ import { SignOnResponse } from './signon';
5
+ export type OFX = {
6
+ SIGNONMSGSRSV1: SignOnResponse;
7
+ BANKMSGSRSV1: BankResponse;
8
+ CREDITCARDMSGSRSV1: CreditCardResponse;
9
+ };
10
+ export type OfxStructure = {
11
+ OFX: OFX;
12
+ };
13
+ export type OfxResponse = MetaData & OfxStructure;
@@ -0,0 +1,18 @@
1
+ export type SignOnResponse = {
2
+ SONRS: SignOnStatus;
3
+ };
4
+ export type SignOnStatus = {
5
+ STATUS: Status;
6
+ DTSERVER: string;
7
+ LANGUAGE: string;
8
+ FI?: FinancialInstitution;
9
+ };
10
+ export type Status = {
11
+ CODE: number | string;
12
+ SEVERITY: 'INFO' | 'WARN' | 'ERROR';
13
+ MESSAGE?: string;
14
+ };
15
+ export type FinancialInstitution = {
16
+ ORG: string;
17
+ FID: string;
18
+ };
@@ -1,4 +1,4 @@
1
- import { STRTTRN } from '../@types/ofx';
2
1
  import { Types } from '../@types/common';
2
+ import type { StatementTransaction } from '../@types/ofx/common';
3
3
  export declare const extractType: (content: string) => Types;
4
- export declare function isDebt(strttrn: STRTTRN): boolean;
4
+ export declare function isDebt(transaction: StatementTransaction): boolean;
@@ -1,5 +1,5 @@
1
- import type { STRTTRN as STRTTRNType } from '../@types/ofx';
2
1
  import { ExtractorConfig } from '../@types/common';
2
+ import type { StatementTransaction } from '../@types/ofx/common';
3
3
  export declare function fixJsonProblems(content: string): string;
4
4
  export declare const extractFinancialInstitutionTransactionId: (fitid: string) => string;
5
5
  export declare const isDateField: (field: string) => boolean;
@@ -38,7 +38,7 @@ export declare function extractMetaDataFromXml(data: string[]): string[];
38
38
  export declare function convertMetaDataToObject(stringList: string[], nativeTypes: boolean): {
39
39
  [key: string]: any;
40
40
  };
41
- export declare function getTransactionsSummary(STRTTRN: STRTTRNType[]): {
41
+ export declare function getTransactionsSummary(transations: StatementTransaction[]): {
42
42
  credit: number;
43
43
  debit: number;
44
44
  amountOfCredits: number;
@@ -1,10 +1,9 @@
1
- // Ofx-data-extractor v1.4.3 Copyright (c) 2024 Fábio Pereira França
2
- const p=/<\/\w+>/g,N=/<\w+>/g,T="<BANKMSGSRSV1>",d="</BANKMSGSRSV1>",g="<CREDITCARDMSGSRSV1>",S="</CREDITCARDMSGSRSV1>",R="<STMTTRN>",u="</STMTTRN>",x="_#_",M=new RegExp(x,"g"),L=[T,R,g],b=[d,S,u];function _(e){const t=e.slice(0,4),n=e.slice(4,6),r=e.slice(6,8),s=e.slice(8,10),a=e.slice(10,12),i=e.slice(12,14);return{yyyy:t,yy:t.slice(2),y:t,MM:n,M:n,dd:r,d:r,hh:s,h:s,mm:a,m:a,ss:i,s:i}}function k(e,t){const n=_(e);let r=t;for(const[s,a]of Object.entries(n))r=r.replace(s,a);return r}var l;(function(e){e.BANK="BANK",e.CREDIT_CARD="CREDIT_CARD"})(l||(l={}));const G=e=>e.includes(T)?l.BANK:l.CREDIT_CARD;function F(e){const t=String(e.TRNTYPE).toLocaleLowerCase();return t==="1"||t.startsWith("deb")}function f(e){const t=e.replace(/(\\)/g,"\\\\").replace(p,n=>A(n,!0)).replace(N,n=>w(n,!0)).replace(`
3
- `,"").replace(/(},})/g,"}}").replace(/(}")/g,'},"').replace(/(]")/g,'],"').replace(/(},])/g,"}]").replace(/(,})/g,"}").replace(/,\s*}/g,"}").replace(/(,",)/,",").replace(M,'\\"').slice(0,-1);return t.endsWith(",")?t.slice(0,-1):t}const K=e=>JSON.stringify({date:e.slice(0,12),transactionCode:e.slice(12,19),protocol:e.slice(19)}),J=e=>e.startsWith("DT"),D=e=>e.trim();function w(e,t=!1){return L.includes(e)&&!t?e:e.replace(/[<]/g,`
4
- "`).replace(/[>]/g,'":{')}function A(e,t=!1){return b.includes(e)&&!t?`
1
+ // Ofx-data-extractor v1.4.4 Copyright (c) 2025 Fábio Pereira França
2
+ const E=/<\/\w+>/g,N=/<\w+>/g,u="<BANKMSGSRSV1>",d="</BANKMSGSRSV1>",g="<CREDITCARDMSGSRSV1>",S="</CREDITCARDMSGSRSV1>",R="<STMTTRN>",T="</STMTTRN>",x="_#_",M=new RegExp(x,"g"),b=[u,R,g],L=[d,S,T];function _(e){const t=e.slice(0,4),n=e.slice(4,6),r=e.slice(6,8),s=e.slice(8,10),a=e.slice(10,12),i=e.slice(12,14);return{yyyy:t,yy:t.slice(2),y:t,MM:n,M:n,dd:r,d:r,hh:s,h:s,mm:a,m:a,ss:i,s:i}}function k(e,t){const n=_(e);let r=t;for(const[s,a]of Object.entries(n))r=r.replace(s,a);return r}var l;(function(e){e.BANK="BANK",e.CREDIT_CARD="CREDIT_CARD"})(l||(l={}));const G=["debit","fee","srvchg","atm","pos","check","payment","directdebit","cash","repeatpmt"],F=e=>e.includes(u)?l.BANK:l.CREDIT_CARD;function K(e){if(String(e.TRNAMT).startsWith("-"))return!0;const t=String(e.TRNTYPE).toLocaleLowerCase();return t==="1"||G.includes(t)}function f(e){const t=e.replace(/(\\)/g,"\\\\").replace(E,n=>A(n,!0)).replace(N,n=>w(n,!0)).replace(/(},})/g,"}}").replace(/(}")/g,'},"').replace(/(]")/g,'],"').replace(/(},])/g,"}]").replace(/(,})/g,"}").replace(/,\s*}/g,"}").replace(/(,",)/,",").replace(M,'\\"').slice(0,-1);return t.endsWith(",")?t.slice(0,-1):t}const J=e=>JSON.stringify({date:e.slice(0,12),transactionCode:e.slice(12,19),protocol:e.slice(19)}),P=e=>e.startsWith("DT"),D=e=>e.trim();function w(e,t=!1){return b.includes(e)&&!t?e:e.replace(/[<]/g,`
3
+ "`).replace(/[>]/g,'":{')}function A(e,t=!1){return L.includes(e)&&!t?`
5
4
  ${e}`:`},
6
- `}function P({fitId:e,fitValue:t}){return e==="separated"?K(t):`"${t}",`}function $(e){return e.search(",")>e.search(".")?e.replace(/[.]/g,"").replace(/[,]/g,"."):e.replace(/[,]/g,"")}function X({dateString:e,formatDate:t="y-M-d"}){return k(e,t)}function V(e){let t=e.value.replace(/[{]/g,"").replace(/(},)/g,"").replace(/["]/g,x);const n=e.field.replace(/['"]/g,"");return n.endsWith("AMT")&&(t=$(t)),J(n)&&(t=X({dateString:t,formatDate:e.formatDate})),n==="FITID"?P({fitId:e.fitId,fitValue:t}):e.nativeTypes&&B(n,t)?`${Number(t)},`:`"${t}",`}function W(e,t){let n=e;return e.match(/{(\w|\W)+/)&&(n=n.replace(/({(\w|\W)+)$/,r=>V({field:n.slice(0,n.indexOf(":")),value:r,...t}))),n}function B(e,t){return e.endsWith("ID")||e.endsWith("NUM")?!1:!isNaN(Number(t))}function O(e){const t=e.indexOf(R),n=e.lastIndexOf(u)+u.length,r=e.substring(t,n),s=new RegExp(R,"g"),a=new RegExp(u,"g"),i=`"STRTTRN":[${r.replace(s,"{").replace(a,"},")}]`;return{oldListText:e,newListText:e.replace(r,i)}}function m(e){if(!(e.indexOf(T)>0))return{newBankStatementTransactions:null,oldBankStatementTransactions:null};const n=O(e.substring(e.indexOf(T),e.indexOf(d)+d.length));return{newBankStatementTransactions:n.newListText,oldBankStatementTransactions:n.oldListText}}function h(e){if(!(e.indexOf(g)>0))return{newCreditCardStatementTransactions:null,oldCreditCardStatementTransactions:null};const n=e.substring(e.indexOf(g),e.indexOf(S)+S.length),r=O(n);return{newCreditCardStatementTransactions:r.newListText,oldCreditCardStatementTransactions:r.oldListText}}function z(e){const t=[];for(const n of e)t.push(...n.replace("<?xml"," ").replace("<?OFX"," ").replace("?>"," ").split(" ").filter(Boolean).map(D).map(r=>r.replace("=",":").replace(/["]/g,"")));return t}function j(e,t){const n={};e.join("").search("<?")>-1&&(e=z(e));for(const r of e){const[s,a]=r.split(":"),i=s.replace(`
7
- `,"").toUpperCase();n[i]=t&&B(s,a)?Number(a):String(a).replace(/\?>/,"")}return n}function H(e){return e.reduce((t,n)=>{const r=Math.abs(+n.TRNAMT);return F(n)?(t.amountOfDebits++,t.debit+=r,t):(t.amountOfCredits++,t.credit+=r,t)},{credit:0,debit:0,amountOfCredits:0,amountOfDebits:0})}class U{config;internConfig={};constructor(t){this.config=t,this.internConfig=t}getConfig(){return this.internConfig}sanitizeRow(t){return W(t,this.internConfig)}getPartialJsonData(t){const[n,r]=t.split("<OFX>"),s="<OFX>"+r,{sanitizeRow:a}=this;return s.replace(/<([^\/][^>]*)>/g,`
8
- <$1>`).replace(p,i=>A(i)).replace(N,i=>w(i)).split(`
9
- `).map(D).filter(Boolean).map(a,this).join("")}}function I(e){return e.toString()}async function E(e){return await new Promise((n,r)=>{if(typeof window<"u"&&window.FileReader){const s=new window.FileReader;s.onload=a=>n(a.target.result),s.onerror=a=>r(a.target.error),s.readAsText(e)}else r(new Error("FileReader is not available in this environment."))})}class c{data;dataRead="";constructor(t){this.data=t,t&&(this.dataRead=t)}getData(){return this.dataRead}fromString(t){return new c(t)}fromBuffer(t){return new c(I(t))}async fromBlob(t){return new c(await E(t))}static fromString(t){return new c(t)}static fromBuffer(t){return new c(I(t))}static async fromBlob(t){return new c(await E(t))}}class v{configInstance={}}class y extends v{setConfig(t){this.configInstance=t}getBankTransferList(t){const{newBankStatementTransactions:n}=m(this.configInstance.getPartialJsonData(t));return n?JSON.parse(`{${f(n)}}`)?.BANKMSGSRSV1?.STMTTRNRS?.STMTRS?.BANKTRANLIST?.STRTTRN:[]}getCreditCardTransferList(t){const{newCreditCardStatementTransactions:n}=h(this.configInstance.getPartialJsonData(t));return n?JSON.parse(`{${f(n)}}`)?.CREDITCARDMSGSRSV1?.CCSTMTTRNRS?.CCSTMTRS?.BANKTRANLIST?.STRTTRN:[]}getTransactionsSummary(t){const n=this.getContent(t),{DTEND:r,DTSTART:s,STRTTRN:a}=n.OFX.BANKMSGSRSV1.STMTTRNRS.STMTRS.BANKTRANLIST,i=H(a);return{dateStart:s,dateEnd:r,...i}}getContent(t){const n=this.configInstance.getPartialJsonData(t),{newBankStatementTransactions:r,oldBankStatementTransactions:s}=m(n),{newCreditCardStatementTransactions:a,oldCreditCardStatementTransactions:i}=h(n);let o=n;return r&&(o=o.replace(s,r)),a&&(o=o.replace(i,a)),JSON.parse(`{${f(o)}}`)}}class Y{customExtractor;customExtractorInstance;dataReaderInstance=new c("");constructor(t){this.customExtractor=t,this.customExtractorInstance=t||new y,this.config({})}data(t){return this.dataReaderInstance=t,this}config(t){return this.customExtractorInstance.setConfig(new U(t)),this}getType(){return G(this.dataReaderInstance.getData())}getHeaders(){const[t]=this.dataReaderInstance.getData().split("<OFX>");return j(t.split(`
10
- `).filter(n=>!!n.trim().length),!!this.customExtractorInstance.configInstance.getConfig().nativeTypes)}getBankTransferList(){return this.customExtractorInstance.getBankTransferList(this.dataReaderInstance.getData())}getCreditCardTransferList(){return this.customExtractorInstance.getCreditCardTransferList(this.dataReaderInstance.getData())}getTransactionsSummary(){return this.customExtractorInstance.getTransactionsSummary(this.dataReaderInstance.getData())}getContent(){return this.customExtractorInstance.getContent(this.dataReaderInstance.getData())}toJson(){const t=this.getHeaders(),n=this.customExtractorInstance.getContent(this.dataReaderInstance.getData());return{...t,...n}}}class C{extractor;constructor(t,n){this.extractor=new Y(new y),this.extractor.data(new c(t)),this.extractor.config(n||{})}getType(){return this.extractor.getType()}static fromBuffer(t){return new C(c.fromBuffer(t).getData())}static async fromBlob(t){const n=await c.fromBlob(t);return new C(n.getData())}config(t){return this.extractor.config(t),this}getHeaders(){return this.extractor.getHeaders()}getBankTransferList(){return this.extractor.getBankTransferList()}getCreditCardTransferList(){return this.extractor.getCreditCardTransferList()}getTransactionsSummary(){return this.extractor.getTransactionsSummary()}getContent(){return this.extractor.getContent()}toJson(){return this.extractor.toJson()}}export{Y as Extractor,C as Ofx,y as OfxExtractor,c as Reader,E as blobToString,I as bufferToString,f as fixJsonProblems,k as formatDate};
5
+ `}function X({fitId:e,fitValue:t}){return e==="separated"?J(t):`"${t}",`}function $(e){return e.search(",")>e.search(".")?e.replace(/[.]/g,"").replace(/[,]/g,"."):e.replace(/[,]/g,"")}function V({dateString:e,formatDate:t="y-M-d"}){return k(e,t)}function W(e){let t=e.value.replace(/[{]/g,"").replace(/(},)/g,"").replace(/["]/g,x);const n=e.field.replace(/['"]/g,"");return n.endsWith("AMT")&&(t=$(t)),P(n)&&(t=V({dateString:t,formatDate:e.formatDate})),n==="FITID"?X({fitId:e.fitId,fitValue:t}):e.nativeTypes&&B(n,t)?`${Number(t)},`:`"${t}",`}function z(e,t){let n=e;return e.match(/{(\w|\W)+/)&&(n=n.replace(/({(\w|\W)+)$/,r=>W({field:n.slice(0,n.indexOf(":")),value:r,...t}))),n}function B(e,t){return e.endsWith("ID")||e.endsWith("NUM")?!1:!isNaN(Number(t))}function y(e){const t=e.indexOf(R),n=e.lastIndexOf(T)+T.length,r=e.substring(t,n),s=new RegExp(R,"g"),a=new RegExp(T,"g"),i=`"STRTTRN":[${r.replace(s,"{").replace(a,"},")}]`;return{oldListText:e,newListText:e.replace(r,i)}}function m(e){if(!(e.indexOf(u)>0))return{newBankStatementTransactions:null,oldBankStatementTransactions:null};const n=y(e.substring(e.indexOf(u),e.indexOf(d)+d.length));return{newBankStatementTransactions:n.newListText,oldBankStatementTransactions:n.oldListText}}function h(e){if(!(e.indexOf(g)>0))return{newCreditCardStatementTransactions:null,oldCreditCardStatementTransactions:null};const n=e.substring(e.indexOf(g),e.indexOf(S)+S.length),r=y(n);return{newCreditCardStatementTransactions:r.newListText,oldCreditCardStatementTransactions:r.oldListText}}function j(e){const t=[];for(const n of e)t.push(...n.replace("<?xml"," ").replace("<?OFX"," ").replace("?>"," ").split(" ").filter(Boolean).map(D).map(r=>r.replace("=",":").replace(/["]/g,"")));return t}function H(e,t){const n={};e.join("").search("<?")>-1&&(e=j(e));for(const r of e){const[s,a]=r.split(":"),i=s.replace(`
6
+ `,"").toUpperCase();n[i]=t&&B(s,a)?Number(a):String(a).replace(/\?>/,"")}return n}function U(e){return e.reduce((t,n)=>{const r=Math.abs(+n.TRNAMT);return K(n)?(t.amountOfDebits++,t.debit+=r,t):(t.amountOfCredits++,t.credit+=r,t)},{credit:0,debit:0,amountOfCredits:0,amountOfDebits:0})}class v{config;internConfig={};constructor(t){this.config=t,this.internConfig=t}getConfig(){return this.internConfig}sanitizeRow(t){return z(t,this.internConfig)}getPartialJsonData(t){const[n,r]=t.split("<OFX>"),s="<OFX>"+r,{sanitizeRow:a}=this;return s.replace(/<(?=[^\/])/g,`
7
+ <`).replace(E,i=>A(i)).replace(N,i=>w(i)).split(`
8
+ `).map(D).filter(Boolean).map(a,this).join("")}}function I(e){return e.toString()}async function p(e){return await new Promise((n,r)=>{if(typeof window<"u"&&window.FileReader){const s=new window.FileReader;s.onload=a=>n(a.target.result),s.onerror=a=>r(a.target.error),s.readAsText(e)}else r(new Error("FileReader is not available in this environment."))})}class c{data;dataRead="";constructor(t){this.data=t,t&&(this.dataRead=t)}getData(){return this.dataRead}fromString(t){return new c(t)}fromBuffer(t){return new c(I(t))}async fromBlob(t){return new c(await p(t))}static fromString(t){return new c(t)}static fromBuffer(t){return new c(I(t))}static async fromBlob(t){return new c(await p(t))}}class Y{configInstance={}}class O extends Y{setConfig(t){this.configInstance=t}getBankTransferList(t){const{newBankStatementTransactions:n}=m(this.configInstance.getPartialJsonData(t));return n?JSON.parse(`{${f(n)}}`)?.BANKMSGSRSV1?.STMTTRNRS?.STMTRS?.BANKTRANLIST?.STRTTRN:[]}getCreditCardTransferList(t){const{newCreditCardStatementTransactions:n}=h(this.configInstance.getPartialJsonData(t));return n?JSON.parse(`{${f(n)}}`)?.CREDITCARDMSGSRSV1?.CCSTMTTRNRS?.CCSTMTRS?.BANKTRANLIST?.STRTTRN:[]}getTransactionsSummary(t){const n=this.getContent(t),{DTEND:r,DTSTART:s,...a}=n.OFX.BANKMSGSRSV1.STMTTRNRS.STMTRS.BANKTRANLIST,i=U(a.STMTTRN||a.STRTTRN);return{dateStart:s,dateEnd:r,...i}}getContent(t){const n=this.configInstance.getPartialJsonData(t),{newBankStatementTransactions:r,oldBankStatementTransactions:s}=m(n),{newCreditCardStatementTransactions:a,oldCreditCardStatementTransactions:i}=h(n);let o=n;return r&&(o=o.replace(s,r)),a&&(o=o.replace(i,a)),JSON.parse(`{${f(o)}}`)}}class Q{customExtractor;customExtractorInstance;dataReaderInstance=new c("");constructor(t){this.customExtractor=t,this.customExtractorInstance=t||new O,this.config({})}data(t){return this.dataReaderInstance=t,this}config(t){return this.customExtractorInstance.setConfig(new v(t)),this}getType(){return F(this.dataReaderInstance.getData())}getHeaders(){const[t]=this.dataReaderInstance.getData().split("<OFX>");return H(t.split(`
9
+ `).filter(n=>!!n.trim().length),!!this.customExtractorInstance.configInstance.getConfig().nativeTypes)}getBankTransferList(){return this.customExtractorInstance.getBankTransferList(this.dataReaderInstance.getData())}getCreditCardTransferList(){return this.customExtractorInstance.getCreditCardTransferList(this.dataReaderInstance.getData())}getTransactionsSummary(){return this.customExtractorInstance.getTransactionsSummary(this.dataReaderInstance.getData())}getContent(){return this.customExtractorInstance.getContent(this.dataReaderInstance.getData())}toJson(){const t=this.getHeaders(),n=this.customExtractorInstance.getContent(this.dataReaderInstance.getData());return{...t,...n}}}class C{extractor;constructor(t,n){this.extractor=new Q(new O),this.extractor.data(new c(t)),this.extractor.config(n||{})}getType(){return this.extractor.getType()}static fromBuffer(t){return new C(c.fromBuffer(t).getData())}static async fromBlob(t){const n=await c.fromBlob(t);return new C(n.getData())}config(t){return this.extractor.config(t),this}getHeaders(){return this.extractor.getHeaders()}getBankTransferList(){return this.extractor.getBankTransferList()}getCreditCardTransferList(){return this.extractor.getCreditCardTransferList()}getTransactionsSummary(){return this.extractor.getTransactionsSummary()}getContent(){return this.extractor.getContent()}toJson(){return this.extractor.toJson()}}export{Q as Extractor,C as Ofx,O as OfxExtractor,c as Reader,p as blobToString,I as bufferToString,f as fixJsonProblems,k as formatDate};
@@ -2,7 +2,8 @@ import type { ExtractorConfig, MetaData, TransactionsSummary } from '../@types/c
2
2
  import { IExtractor } from '../interfaces/extractor.interface';
3
3
  import { CustomExtractor } from '../interfaces/custom-extractor.interface';
4
4
  import { Reader } from './reader';
5
- import { OfxResponse, OfxStructure, STRTTRN } from '../@types/ofx';
5
+ import { OfxResponse, OfxStructure } from '../@types/ofx/index';
6
+ import { StatementTransaction } from '../@types/ofx/common';
6
7
  export declare class Extractor<T = any> implements IExtractor<T> {
7
8
  private readonly customExtractor?;
8
9
  private customExtractorInstance;
@@ -12,8 +13,8 @@ export declare class Extractor<T = any> implements IExtractor<T> {
12
13
  config(config: ExtractorConfig): this;
13
14
  getType(): import("../@types/common").Types;
14
15
  getHeaders(): MetaData;
15
- getBankTransferList(): STRTTRN[];
16
- getCreditCardTransferList(): STRTTRN[];
16
+ getBankTransferList(): StatementTransaction[];
17
+ getCreditCardTransferList(): StatementTransaction[];
17
18
  getTransactionsSummary(): TransactionsSummary;
18
19
  getContent(): OfxStructure;
19
20
  toJson(): OfxResponse;
@@ -1,4 +1,4 @@
1
- import { OfxStructure } from '../@types/ofx';
1
+ import { OfxStructure } from '../@types/ofx/index';
2
2
  import { CustomExtractor } from '../interfaces/custom-extractor.interface';
3
3
  import { Config } from '../common/config';
4
4
  import { TransactionsSummary } from '../@types/common';
package/dist/index.d.ts CHANGED
@@ -4,7 +4,8 @@ export { fixJsonProblems } from './common/parse';
4
4
  export { formatDate } from './common/date';
5
5
  export type { IExtractor } from './interfaces/extractor.interface';
6
6
  export type { CustomExtractor } from './interfaces/custom-extractor.interface';
7
- export type { OfxResponse, OfxStructure, BankTransferList } from './@types/ofx';
7
+ export type { OfxResponse, OfxStructure } from './@types/ofx/index';
8
+ export type { BankTransactionList } from './@types/ofx/banking';
8
9
  export { Reader } from './implementations/reader';
9
10
  export { OfxExtractor } from './implementations/ofx-extractor';
10
11
  export { Extractor } from './implementations/extractor';
@@ -1,11 +1,12 @@
1
- import { OfxResponse, OfxStructure, STRTTRN } from '../@types/ofx';
1
+ import { OfxResponse, OfxStructure } from '../@types/ofx/index';
2
2
  import { ExtractorConfig, MetaData, TransactionsSummary, Types } from '../@types/common';
3
+ import type { StatementTransaction } from '../@types/ofx/common';
3
4
  export interface IExtractor<T> {
4
5
  getType(): Types;
5
6
  config(config: ExtractorConfig): this;
6
7
  getHeaders(): MetaData;
7
- getBankTransferList(): STRTTRN[];
8
- getCreditCardTransferList(): STRTTRN[];
8
+ getBankTransferList(): StatementTransaction[];
9
+ getCreditCardTransferList(): StatementTransaction[];
9
10
  getTransactionsSummary(): TransactionsSummary;
10
11
  getContent(): OfxStructure;
11
12
  toJson(): OfxResponse;
@@ -1,16 +1,17 @@
1
1
  /// <reference types="node" />
2
- import { MetaData } from '../@types/common';
3
- import { OfxResponse, OfxStructure, STRTTRN, OfxConfig } from '../@types/ofx';
2
+ import { ExtractorConfig, MetaData } from '../@types/common';
3
+ import { OfxResponse, OfxStructure } from '../@types/ofx/index';
4
+ import { StatementTransaction } from '../@types/ofx/common';
4
5
  export declare class Ofx {
5
6
  private extractor;
6
- constructor(data: string, config?: OfxConfig);
7
+ constructor(data: string, config?: ExtractorConfig);
7
8
  getType(): import("../@types/common").Types;
8
9
  static fromBuffer(data: Buffer): Ofx;
9
10
  static fromBlob(blob: Blob): Promise<Ofx>;
10
- config(config: OfxConfig): this;
11
+ config(config: ExtractorConfig): this;
11
12
  getHeaders(): MetaData;
12
- getBankTransferList(): STRTTRN[];
13
- getCreditCardTransferList(): STRTTRN[];
13
+ getBankTransferList(): StatementTransaction[];
14
+ getCreditCardTransferList(): StatementTransaction[];
14
15
  getTransactionsSummary(): import("../@types/common").TransactionsSummary;
15
16
  getContent(): OfxStructure;
16
17
  toJson(): OfxResponse;
@@ -1,10 +1,9 @@
1
- // Ofx-data-extractor v1.4.3 Copyright (c) 2024 Fábio Pereira França
2
- (function(o,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(o=typeof globalThis<"u"?globalThis:o||self,u(o.ofx={}))})(this,function(o){"use strict";const u=/<\/\w+>/g,N=/<\w+>/g,f="<BANKMSGSRSV1>",R="</BANKMSGSRSV1>",m="<CREDITCARDMSGSRSV1>",C="</CREDITCARDMSGSRSV1>",h="<STMTTRN>",l="</STMTTRN>",p="_#_",_=new RegExp(p,"g"),k=[f,h,m],G=[R,C,l];function F(e){const t=e.slice(0,4),n=e.slice(4,6),r=e.slice(6,8),s=e.slice(8,10),a=e.slice(10,12),i=e.slice(12,14);return{yyyy:t,yy:t.slice(2),y:t,MM:n,M:n,dd:r,d:r,hh:s,h:s,mm:a,m:a,ss:i,s:i}}function D(e,t){const n=F(e);let r=t;for(const[s,a]of Object.entries(n))r=r.replace(s,a);return r}var d;(function(e){e.BANK="BANK",e.CREDIT_CARD="CREDIT_CARD"})(d||(d={}));const J=e=>e.includes(f)?d.BANK:d.CREDIT_CARD;function K(e){const t=String(e.TRNTYPE).toLocaleLowerCase();return t==="1"||t.startsWith("deb")}function g(e){const t=e.replace(/(\\)/g,"\\\\").replace(u,n=>B(n,!0)).replace(N,n=>A(n,!0)).replace(`
3
- `,"").replace(/(},})/g,"}}").replace(/(}")/g,'},"').replace(/(]")/g,'],"').replace(/(},])/g,"}]").replace(/(,})/g,"}").replace(/,\s*}/g,"}").replace(/(,",)/,",").replace(_,'\\"').slice(0,-1);return t.endsWith(",")?t.slice(0,-1):t}const P=e=>JSON.stringify({date:e.slice(0,12),transactionCode:e.slice(12,19),protocol:e.slice(19)}),$=e=>e.startsWith("DT"),w=e=>e.trim();function A(e,t=!1){return k.includes(e)&&!t?e:e.replace(/[<]/g,`
4
- "`).replace(/[>]/g,'":{')}function B(e,t=!1){return G.includes(e)&&!t?`
1
+ // Ofx-data-extractor v1.4.4 Copyright (c) 2025 Fábio Pereira França
2
+ (function(c,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(c=typeof globalThis<"u"?globalThis:c||self,u(c.ofx={}))})(this,function(c){"use strict";const u=/<\/\w+>/g,N=/<\w+>/g,f="<BANKMSGSRSV1>",R="</BANKMSGSRSV1>",m="<CREDITCARDMSGSRSV1>",C="</CREDITCARDMSGSRSV1>",h="<STMTTRN>",d="</STMTTRN>",x="_#_",_=new RegExp(x,"g"),k=[f,h,m],G=[R,C,d];function F(e){const t=e.slice(0,4),n=e.slice(4,6),r=e.slice(6,8),s=e.slice(8,10),a=e.slice(10,12),i=e.slice(12,14);return{yyyy:t,yy:t.slice(2),y:t,MM:n,M:n,dd:r,d:r,hh:s,h:s,mm:a,m:a,ss:i,s:i}}function D(e,t){const n=F(e);let r=t;for(const[s,a]of Object.entries(n))r=r.replace(s,a);return r}var l;(function(e){e.BANK="BANK",e.CREDIT_CARD="CREDIT_CARD"})(l||(l={}));const J=["debit","fee","srvchg","atm","pos","check","payment","directdebit","cash","repeatpmt"],K=e=>e.includes(f)?l.BANK:l.CREDIT_CARD;function P(e){if(String(e.TRNAMT).startsWith("-"))return!0;const t=String(e.TRNTYPE).toLocaleLowerCase();return t==="1"||J.includes(t)}function g(e){const t=e.replace(/(\\)/g,"\\\\").replace(u,n=>y(n,!0)).replace(N,n=>A(n,!0)).replace(/(},})/g,"}}").replace(/(}")/g,'},"').replace(/(]")/g,'],"').replace(/(},])/g,"}]").replace(/(,})/g,"}").replace(/,\s*}/g,"}").replace(/(,",)/,",").replace(_,'\\"').slice(0,-1);return t.endsWith(",")?t.slice(0,-1):t}const X=e=>JSON.stringify({date:e.slice(0,12),transactionCode:e.slice(12,19),protocol:e.slice(19)}),$=e=>e.startsWith("DT"),w=e=>e.trim();function A(e,t=!1){return k.includes(e)&&!t?e:e.replace(/[<]/g,`
3
+ "`).replace(/[>]/g,'":{')}function y(e,t=!1){return G.includes(e)&&!t?`
5
4
  ${e}`:`},
6
- `}function X({fitId:e,fitValue:t}){return e==="separated"?P(t):`"${t}",`}function V(e){return e.search(",")>e.search(".")?e.replace(/[.]/g,"").replace(/[,]/g,"."):e.replace(/[,]/g,"")}function W({dateString:e,formatDate:t="y-M-d"}){return D(e,t)}function j(e){let t=e.value.replace(/[{]/g,"").replace(/(},)/g,"").replace(/["]/g,p);const n=e.field.replace(/['"]/g,"");return n.endsWith("AMT")&&(t=V(t)),$(n)&&(t=W({dateString:t,formatDate:e.formatDate})),n==="FITID"?X({fitId:e.fitId,fitValue:t}):e.nativeTypes&&O(n,t)?`${Number(t)},`:`"${t}",`}function z(e,t){let n=e;return e.match(/{(\w|\W)+/)&&(n=n.replace(/({(\w|\W)+)$/,r=>j({field:n.slice(0,n.indexOf(":")),value:r,...t}))),n}function O(e,t){return e.endsWith("ID")||e.endsWith("NUM")?!1:!isNaN(Number(t))}function y(e){const t=e.indexOf(h),n=e.lastIndexOf(l)+l.length,r=e.substring(t,n),s=new RegExp(h,"g"),a=new RegExp(l,"g"),i=`"STRTTRN":[${r.replace(s,"{").replace(a,"},")}]`;return{oldListText:e,newListText:e.replace(r,i)}}function b(e){if(!(e.indexOf(f)>0))return{newBankStatementTransactions:null,oldBankStatementTransactions:null};const n=y(e.substring(e.indexOf(f),e.indexOf(R)+R.length));return{newBankStatementTransactions:n.newListText,oldBankStatementTransactions:n.oldListText}}function M(e){if(!(e.indexOf(m)>0))return{newCreditCardStatementTransactions:null,oldCreditCardStatementTransactions:null};const n=e.substring(e.indexOf(m),e.indexOf(C)+C.length),r=y(n);return{newCreditCardStatementTransactions:r.newListText,oldCreditCardStatementTransactions:r.oldListText}}function H(e){const t=[];for(const n of e)t.push(...n.replace("<?xml"," ").replace("<?OFX"," ").replace("?>"," ").split(" ").filter(Boolean).map(w).map(r=>r.replace("=",":").replace(/["]/g,"")));return t}function U(e,t){const n={};e.join("").search("<?")>-1&&(e=H(e));for(const r of e){const[s,a]=r.split(":"),i=s.replace(`
7
- `,"").toUpperCase();n[i]=t&&O(s,a)?Number(a):String(a).replace(/\?>/,"")}return n}function v(e){return e.reduce((t,n)=>{const r=Math.abs(+n.TRNAMT);return K(n)?(t.amountOfDebits++,t.debit+=r,t):(t.amountOfCredits++,t.credit+=r,t)},{credit:0,debit:0,amountOfCredits:0,amountOfDebits:0})}class Y{config;internConfig={};constructor(t){this.config=t,this.internConfig=t}getConfig(){return this.internConfig}sanitizeRow(t){return z(t,this.internConfig)}getPartialJsonData(t){const[n,r]=t.split("<OFX>"),s="<OFX>"+r,{sanitizeRow:a}=this;return s.replace(/<([^\/][^>]*)>/g,`
8
- <$1>`).replace(u,i=>B(i)).replace(N,i=>A(i)).split(`
9
- `).map(w).filter(Boolean).map(a,this).join("")}}function E(e){return e.toString()}async function I(e){return await new Promise((n,r)=>{if(typeof window<"u"&&window.FileReader){const s=new window.FileReader;s.onload=a=>n(a.target.result),s.onerror=a=>r(a.target.error),s.readAsText(e)}else r(new Error("FileReader is not available in this environment."))})}class c{data;dataRead="";constructor(t){this.data=t,t&&(this.dataRead=t)}getData(){return this.dataRead}fromString(t){return new c(t)}fromBuffer(t){return new c(E(t))}async fromBlob(t){return new c(await I(t))}static fromString(t){return new c(t)}static fromBuffer(t){return new c(E(t))}static async fromBlob(t){return new c(await I(t))}}class Q{configInstance={}}class x extends Q{setConfig(t){this.configInstance=t}getBankTransferList(t){const{newBankStatementTransactions:n}=b(this.configInstance.getPartialJsonData(t));return n?JSON.parse(`{${g(n)}}`)?.BANKMSGSRSV1?.STMTTRNRS?.STMTRS?.BANKTRANLIST?.STRTTRN:[]}getCreditCardTransferList(t){const{newCreditCardStatementTransactions:n}=M(this.configInstance.getPartialJsonData(t));return n?JSON.parse(`{${g(n)}}`)?.CREDITCARDMSGSRSV1?.CCSTMTTRNRS?.CCSTMTRS?.BANKTRANLIST?.STRTTRN:[]}getTransactionsSummary(t){const n=this.getContent(t),{DTEND:r,DTSTART:s,STRTTRN:a}=n.OFX.BANKMSGSRSV1.STMTTRNRS.STMTRS.BANKTRANLIST,i=v(a);return{dateStart:s,dateEnd:r,...i}}getContent(t){const n=this.configInstance.getPartialJsonData(t),{newBankStatementTransactions:r,oldBankStatementTransactions:s}=b(n),{newCreditCardStatementTransactions:a,oldCreditCardStatementTransactions:i}=M(n);let T=n;return r&&(T=T.replace(s,r)),a&&(T=T.replace(i,a)),JSON.parse(`{${g(T)}}`)}}class L{customExtractor;customExtractorInstance;dataReaderInstance=new c("");constructor(t){this.customExtractor=t,this.customExtractorInstance=t||new x,this.config({})}data(t){return this.dataReaderInstance=t,this}config(t){return this.customExtractorInstance.setConfig(new Y(t)),this}getType(){return J(this.dataReaderInstance.getData())}getHeaders(){const[t]=this.dataReaderInstance.getData().split("<OFX>");return U(t.split(`
10
- `).filter(n=>!!n.trim().length),!!this.customExtractorInstance.configInstance.getConfig().nativeTypes)}getBankTransferList(){return this.customExtractorInstance.getBankTransferList(this.dataReaderInstance.getData())}getCreditCardTransferList(){return this.customExtractorInstance.getCreditCardTransferList(this.dataReaderInstance.getData())}getTransactionsSummary(){return this.customExtractorInstance.getTransactionsSummary(this.dataReaderInstance.getData())}getContent(){return this.customExtractorInstance.getContent(this.dataReaderInstance.getData())}toJson(){const t=this.getHeaders(),n=this.customExtractorInstance.getContent(this.dataReaderInstance.getData());return{...t,...n}}}class S{extractor;constructor(t,n){this.extractor=new L(new x),this.extractor.data(new c(t)),this.extractor.config(n||{})}getType(){return this.extractor.getType()}static fromBuffer(t){return new S(c.fromBuffer(t).getData())}static async fromBlob(t){const n=await c.fromBlob(t);return new S(n.getData())}config(t){return this.extractor.config(t),this}getHeaders(){return this.extractor.getHeaders()}getBankTransferList(){return this.extractor.getBankTransferList()}getCreditCardTransferList(){return this.extractor.getCreditCardTransferList()}getTransactionsSummary(){return this.extractor.getTransactionsSummary()}getContent(){return this.extractor.getContent()}toJson(){return this.extractor.toJson()}}o.Extractor=L,o.Ofx=S,o.OfxExtractor=x,o.Reader=c,o.blobToString=I,o.bufferToString=E,o.fixJsonProblems=g,o.formatDate=D});
5
+ `}function V({fitId:e,fitValue:t}){return e==="separated"?X(t):`"${t}",`}function W(e){return e.search(",")>e.search(".")?e.replace(/[.]/g,"").replace(/[,]/g,"."):e.replace(/[,]/g,"")}function j({dateString:e,formatDate:t="y-M-d"}){return D(e,t)}function z(e){let t=e.value.replace(/[{]/g,"").replace(/(},)/g,"").replace(/["]/g,x);const n=e.field.replace(/['"]/g,"");return n.endsWith("AMT")&&(t=W(t)),$(n)&&(t=j({dateString:t,formatDate:e.formatDate})),n==="FITID"?V({fitId:e.fitId,fitValue:t}):e.nativeTypes&&B(n,t)?`${Number(t)},`:`"${t}",`}function H(e,t){let n=e;return e.match(/{(\w|\W)+/)&&(n=n.replace(/({(\w|\W)+)$/,r=>z({field:n.slice(0,n.indexOf(":")),value:r,...t}))),n}function B(e,t){return e.endsWith("ID")||e.endsWith("NUM")?!1:!isNaN(Number(t))}function O(e){const t=e.indexOf(h),n=e.lastIndexOf(d)+d.length,r=e.substring(t,n),s=new RegExp(h,"g"),a=new RegExp(d,"g"),i=`"STRTTRN":[${r.replace(s,"{").replace(a,"},")}]`;return{oldListText:e,newListText:e.replace(r,i)}}function b(e){if(!(e.indexOf(f)>0))return{newBankStatementTransactions:null,oldBankStatementTransactions:null};const n=O(e.substring(e.indexOf(f),e.indexOf(R)+R.length));return{newBankStatementTransactions:n.newListText,oldBankStatementTransactions:n.oldListText}}function M(e){if(!(e.indexOf(m)>0))return{newCreditCardStatementTransactions:null,oldCreditCardStatementTransactions:null};const n=e.substring(e.indexOf(m),e.indexOf(C)+C.length),r=O(n);return{newCreditCardStatementTransactions:r.newListText,oldCreditCardStatementTransactions:r.oldListText}}function U(e){const t=[];for(const n of e)t.push(...n.replace("<?xml"," ").replace("<?OFX"," ").replace("?>"," ").split(" ").filter(Boolean).map(w).map(r=>r.replace("=",":").replace(/["]/g,"")));return t}function v(e,t){const n={};e.join("").search("<?")>-1&&(e=U(e));for(const r of e){const[s,a]=r.split(":"),i=s.replace(`
6
+ `,"").toUpperCase();n[i]=t&&B(s,a)?Number(a):String(a).replace(/\?>/,"")}return n}function Y(e){return e.reduce((t,n)=>{const r=Math.abs(+n.TRNAMT);return P(n)?(t.amountOfDebits++,t.debit+=r,t):(t.amountOfCredits++,t.credit+=r,t)},{credit:0,debit:0,amountOfCredits:0,amountOfDebits:0})}class Q{config;internConfig={};constructor(t){this.config=t,this.internConfig=t}getConfig(){return this.internConfig}sanitizeRow(t){return H(t,this.internConfig)}getPartialJsonData(t){const[n,r]=t.split("<OFX>"),s="<OFX>"+r,{sanitizeRow:a}=this;return s.replace(/<(?=[^\/])/g,`
7
+ <`).replace(u,i=>y(i)).replace(N,i=>A(i)).split(`
8
+ `).map(w).filter(Boolean).map(a,this).join("")}}function E(e){return e.toString()}async function I(e){return await new Promise((n,r)=>{if(typeof window<"u"&&window.FileReader){const s=new window.FileReader;s.onload=a=>n(a.target.result),s.onerror=a=>r(a.target.error),s.readAsText(e)}else r(new Error("FileReader is not available in this environment."))})}class o{data;dataRead="";constructor(t){this.data=t,t&&(this.dataRead=t)}getData(){return this.dataRead}fromString(t){return new o(t)}fromBuffer(t){return new o(E(t))}async fromBlob(t){return new o(await I(t))}static fromString(t){return new o(t)}static fromBuffer(t){return new o(E(t))}static async fromBlob(t){return new o(await I(t))}}class q{configInstance={}}class p extends q{setConfig(t){this.configInstance=t}getBankTransferList(t){const{newBankStatementTransactions:n}=b(this.configInstance.getPartialJsonData(t));return n?JSON.parse(`{${g(n)}}`)?.BANKMSGSRSV1?.STMTTRNRS?.STMTRS?.BANKTRANLIST?.STRTTRN:[]}getCreditCardTransferList(t){const{newCreditCardStatementTransactions:n}=M(this.configInstance.getPartialJsonData(t));return n?JSON.parse(`{${g(n)}}`)?.CREDITCARDMSGSRSV1?.CCSTMTTRNRS?.CCSTMTRS?.BANKTRANLIST?.STRTTRN:[]}getTransactionsSummary(t){const n=this.getContent(t),{DTEND:r,DTSTART:s,...a}=n.OFX.BANKMSGSRSV1.STMTTRNRS.STMTRS.BANKTRANLIST,i=Y(a.STMTTRN||a.STRTTRN);return{dateStart:s,dateEnd:r,...i}}getContent(t){const n=this.configInstance.getPartialJsonData(t),{newBankStatementTransactions:r,oldBankStatementTransactions:s}=b(n),{newCreditCardStatementTransactions:a,oldCreditCardStatementTransactions:i}=M(n);let T=n;return r&&(T=T.replace(s,r)),a&&(T=T.replace(i,a)),JSON.parse(`{${g(T)}}`)}}class L{customExtractor;customExtractorInstance;dataReaderInstance=new o("");constructor(t){this.customExtractor=t,this.customExtractorInstance=t||new p,this.config({})}data(t){return this.dataReaderInstance=t,this}config(t){return this.customExtractorInstance.setConfig(new Q(t)),this}getType(){return K(this.dataReaderInstance.getData())}getHeaders(){const[t]=this.dataReaderInstance.getData().split("<OFX>");return v(t.split(`
9
+ `).filter(n=>!!n.trim().length),!!this.customExtractorInstance.configInstance.getConfig().nativeTypes)}getBankTransferList(){return this.customExtractorInstance.getBankTransferList(this.dataReaderInstance.getData())}getCreditCardTransferList(){return this.customExtractorInstance.getCreditCardTransferList(this.dataReaderInstance.getData())}getTransactionsSummary(){return this.customExtractorInstance.getTransactionsSummary(this.dataReaderInstance.getData())}getContent(){return this.customExtractorInstance.getContent(this.dataReaderInstance.getData())}toJson(){const t=this.getHeaders(),n=this.customExtractorInstance.getContent(this.dataReaderInstance.getData());return{...t,...n}}}class S{extractor;constructor(t,n){this.extractor=new L(new p),this.extractor.data(new o(t)),this.extractor.config(n||{})}getType(){return this.extractor.getType()}static fromBuffer(t){return new S(o.fromBuffer(t).getData())}static async fromBlob(t){const n=await o.fromBlob(t);return new S(n.getData())}config(t){return this.extractor.config(t),this}getHeaders(){return this.extractor.getHeaders()}getBankTransferList(){return this.extractor.getBankTransferList()}getCreditCardTransferList(){return this.extractor.getCreditCardTransferList()}getTransactionsSummary(){return this.extractor.getTransactionsSummary()}getContent(){return this.extractor.getContent()}toJson(){return this.extractor.toJson()}}c.Extractor=L,c.Ofx=S,c.OfxExtractor=p,c.Reader=o,c.blobToString=I,c.bufferToString=E,c.fixJsonProblems=g,c.formatDate=D});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ofx-data-extractor",
3
- "version": "1.4.3",
3
+ "version": "1.4.5",
4
4
  "keywords": [
5
5
  "ofx",
6
6
  "financial",
@@ -47,6 +47,7 @@
47
47
  "build": "rollup --config",
48
48
  "start": "node dist/index.js",
49
49
  "format": "prettier --write \"src/**/*.ts\"",
50
+ "prepublish": "npm run build",
50
51
  "lint": "tslint -p tsconfig.json"
51
52
  },
52
53
  "devDependencies": {