ofx-data-extractor 1.2.4 → 1.3.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/README.md CHANGED
@@ -94,5 +94,20 @@ The `Ofx` (`constructor` and `config` method) class can be configured with the f
94
94
  - `fitId`: A string that determines how the financial institution transaction ID is handled. Possible values are "separated" (the default) or "included".
95
95
  - `nativeTypes`: A boolean value that determines whether numeric fields should be represented as numbers or strings in the resulting JSON object.
96
96
 
97
+ ### Contributors
98
+ <table>
99
+ <tbody>
100
+ <tr>
101
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/segunadebayo"><img src="https://avatars2.githubusercontent.com/u/6916170?v=4?s=64" width="64px;" alt="Segun Adebayo"/><br /><sub><b>Segun Adebayo</b></sub></a><br /><a href="https://github.com/chakra-ui/chakra-ui/commits?author=segunadebayo" title="Code">💻</a> <a href="#maintenance-segunadebayo" title="Maintenance">🚧</a> <a href="https://github.com/chakra-ui/chakra-ui/commits?author=segunadebayo" title="Documentation">📖</a> <a href="#example-segunadebayo" title="Examples">💡</a> <a href="#design-segunadebayo" title="Design">🎨</a></td>
102
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/tioluwani94"><img src="https://avatars1.githubusercontent.com/u/11310046?v=4?s=64" width="64px;" alt="Tioluwani Kolawole"/><br /><sub><b>Tioluwani Kolawole</b></sub></a><br /><a href="https://github.com/chakra-ui/chakra-ui/commits?author=tioluwani94" title="Documentation">📖</a> <a href="#example-tioluwani94" title="Examples">💡</a> <a href="#maintenance-tioluwani94" title="Maintenance">🚧</a></td>
103
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/devanshj"><img src="https://avatars0.githubusercontent.com/u/30295578?v=4?s=64" width="64px;" alt="Devansh Jethmalani"/><br /><sub><b>Devansh Jethmalani</b></sub></a><br /><a href="https://github.com/chakra-ui/chakra-ui/commits?author=devanshj" title="Code">💻</a></td>
104
+ <td align="center" valign="top" width="14.28%"><a href="http://adrianaleixandre.com"><img src="https://avatars3.githubusercontent.com/u/920212?v=4?s=64" width="64px;" alt="Adrian Aleixandre"/><br /><sub><b>Adrian Aleixandre</b></sub></a><br /><a href="https://github.com/chakra-ui/chakra-ui/commits?author=Vynlar" title="Code">💻</a> <a href="https://github.com/chakra-ui/chakra-ui/commits?author=Vynlar" title="Documentation">📖</a></td>
105
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/lee-reinhardt"><img src="https://avatars1.githubusercontent.com/u/980089?v=4?s=64" width="64px;" alt="Lee"/><br /><sub><b>Lee</b></sub></a><br /><a href="https://github.com/chakra-ui/chakra-ui/commits?author=lee-reinhardt" title="Documentation">📖</a></td>
106
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/kripod"><img src="https://avatars3.githubusercontent.com/u/14854048?v=4?s=64" width="64px;" alt="Kristóf Poduszló"/><br /><sub><b>Kristóf Poduszló</b></sub></a><br /><a href="https://github.com/chakra-ui/chakra-ui/commits?author=kripod" title="Code">💻</a> <a href="#ideas-kripod" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/chakra-ui/chakra-ui/issues?q=author%3Akripod" title="Bug reports">🐛</a> <a href="https://github.com/chakra-ui/chakra-ui/commits?author=kripod" title="Documentation">📖</a></td>
107
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/wKovacs64"><img src="https://avatars1.githubusercontent.com/u/1288694?v=4?s=64" width="64px;" alt="Justin Hall"/><br /><sub><b>Justin Hall</b></sub></a><br /><a href="https://github.com/chakra-ui/chakra-ui/commits?author=wKovacs64" title="Code">💻</a></td>
108
+ </tr>
109
+ </tbody>
110
+ </table
111
+
97
112
  [license-image]: https://img.shields.io/badge/license-MIT-blue.svg?style=flat
98
113
  [license-url]: LICENSE
@@ -0,0 +1,48 @@
1
+ export type MetaData = {
2
+ OFXHEADER: string;
3
+ DATA: string;
4
+ VERSION: string;
5
+ SECURITY: string;
6
+ ENCODING: string;
7
+ CHARSET: string;
8
+ COMPRESSION: string;
9
+ OLDFILEUID: string;
10
+ NEWFILEUID: string;
11
+ };
12
+ export type DateResponse = {
13
+ datetime: string | null;
14
+ date: string | null;
15
+ time: string | null;
16
+ offset: string | null;
17
+ timezone: string | null;
18
+ };
19
+ export type ConfigDate = {
20
+ /**
21
+ * @description supported keys:
22
+ * yy => year -> 2 digits,
23
+ * yyyy or y => year,
24
+ * MM or M => month,
25
+ * dd or d => day,
26
+ * hh or h => hour,
27
+ * mm or m => minute,
28
+ * ss or s => second,
29
+ * O => offset,
30
+ * TZ => timezone
31
+ * @example format: 'y-M-d h:m:s'
32
+ * @returns '2022-02-21 09:00:00'
33
+ */
34
+ formatDate?: string;
35
+ };
36
+ export type ConfigFitId = 'normal' | 'separated';
37
+ export type ExtractorConfig = ConfigDate & {
38
+ fitId?: ConfigFitId;
39
+ nativeTypes?: boolean;
40
+ };
41
+ export type TransactionsSummary = {
42
+ credit: number;
43
+ debit: number;
44
+ amountOfCredits: number;
45
+ amountOfDebits: number;
46
+ dateStart: string;
47
+ dateEnd: string;
48
+ };
@@ -0,0 +1,85 @@
1
+ import type { ConfigDate, ConfigFitId, DateResponse, MetaData } from './common';
2
+ export type Status = {
3
+ CODE: string;
4
+ SEVERITY: string;
5
+ };
6
+ export type BankAccountFrom = {
7
+ BANKID: string;
8
+ ACCTID: string;
9
+ ACCTT: string;
10
+ };
11
+ type TransferType = string;
12
+ export type OfxConfig = ConfigDate & {
13
+ fitId?: ConfigFitId;
14
+ nativeTypes?: boolean;
15
+ };
16
+ export type STRTTRN = {
17
+ TRNTYPE: TransferType;
18
+ DTPOSTED: DateResponse;
19
+ TRNAMT: string;
20
+ FITID: string | {
21
+ date: string;
22
+ protocol: string;
23
+ transactionCode: string;
24
+ };
25
+ CHECKNUM: string;
26
+ MEMO: string;
27
+ };
28
+ export type BankTransferList = {
29
+ DTSTART: DateResponse;
30
+ DTEND: DateResponse;
31
+ STRTTRN: STRTTRN[];
32
+ };
33
+ export type LedGerBal = {
34
+ BALAMT: string;
35
+ DTASOF: DateResponse;
36
+ };
37
+ export type FINANCIAL_INSTITUTION = {
38
+ ORG: string;
39
+ FID: string;
40
+ };
41
+ export type Bank = {
42
+ STMTTRNRS: {
43
+ TRNUID: number;
44
+ STATUS: Status;
45
+ STMTRS: {
46
+ CURDEF: string;
47
+ BANKACCTFROM: BankAccountFrom;
48
+ BANKTRANLIST: BankTransferList;
49
+ LEDGERBAL: LedGerBal;
50
+ MKTGINFO: string;
51
+ };
52
+ };
53
+ };
54
+ export type CreditCard = {
55
+ CCSTMTTRNRS: {
56
+ TRNUID: number;
57
+ STATUS: Status;
58
+ CCSTMTRS: {
59
+ CURDEF: string;
60
+ CCACCTFROM: {
61
+ ACCTID: string;
62
+ };
63
+ BANKTRANLIST: BankTransferList;
64
+ LEDGERBAL: LedGerBal;
65
+ MKTGINFO: string;
66
+ };
67
+ };
68
+ };
69
+ export type OfxStructure = {
70
+ OFX: {
71
+ SIGNONMSGSRSV1: {
72
+ SONRS: {
73
+ STATUS: Status;
74
+ DTSERVER: DateResponse;
75
+ LANGUAGE: string;
76
+ DTACCTUP: DateResponse;
77
+ FI: FINANCIAL_INSTITUTION;
78
+ };
79
+ };
80
+ BANKMSGSRSV1: Bank;
81
+ CREDITCARDMSGSRSV1: CreditCard;
82
+ };
83
+ };
84
+ export type OfxResponse = MetaData & OfxStructure;
85
+ export {};
@@ -0,0 +1,9 @@
1
+ import { ExtractorConfig } from '../@types/common';
2
+ export declare class Config {
3
+ private readonly config;
4
+ private internConfig;
5
+ constructor(config: ExtractorConfig);
6
+ getConfig(): ExtractorConfig;
7
+ sanitizeRow(row: string): string;
8
+ getPartialJsonData(data: string): string;
9
+ }
@@ -0,0 +1,10 @@
1
+ export declare const ELEMENT_CLOSURE_REGEX: RegExp;
2
+ export declare const ELEMENT_OPENING_REGEX: RegExp;
3
+ export declare const BANK_SERVICE_START = "<BANKMSGSRSV1>";
4
+ export declare const BANK_SERVICE_END = "</BANKMSGSRSV1>";
5
+ export declare const CREDIT_CARD_SERVICE_START = "<CREDITCARDMSGSRSV1>";
6
+ export declare const CREDIT_CARD_SERVICE_END = "</CREDITCARDMSGSRSV1>";
7
+ export declare const START_STATEMENT_TRANSACION = "<STMTTRN>";
8
+ export declare const FINISH_STATEMENT_TRANSACTION = "</STMTTRN>";
9
+ export declare const OPENING_TAGS_INITIALLY_IGNORED: string[];
10
+ export declare const CLOSING_TAGS_INITIALLY_IGNORED: string[];
@@ -0,0 +1 @@
1
+ export declare function formatDate(date: string, format: string): string;
@@ -0,0 +1,40 @@
1
+ import type { STRTTRN as STRTTRNType } from '../@types/ofx';
2
+ import { ExtractorConfig } from '../@types/common';
3
+ export declare function fixJsonProblems(content: string): string;
4
+ export declare function extractFinancialInstitutionTransactionId(fitid: string): string;
5
+ export declare function isDateField(field: string): boolean;
6
+ export declare function trim(str: string): string;
7
+ export declare function objectStartReplacer(param: string, force?: boolean): string;
8
+ export declare function objectEndReplacer(param: string, force?: boolean): string;
9
+ export declare function configFinancialInstitutionTransactionId({ fitId, fitValue, }: Pick<ExtractorConfig, 'fitId'> & {
10
+ fitValue: string;
11
+ }): string;
12
+ export declare function sanitizeCurrency(value: string): string;
13
+ type GetDateParams = Pick<ExtractorConfig, 'formatDate'> & {
14
+ dateString: string;
15
+ };
16
+ export declare function getConfiguredDate({ dateString, formatDate: format, }: GetDateParams): string;
17
+ export declare function sanitize(row: string, config: ExtractorConfig): string;
18
+ export declare function isValidNumberToConvert(field: string, value: string): boolean;
19
+ export declare function parseTransactions(content: string): {
20
+ oldListText: string;
21
+ newListText: string;
22
+ };
23
+ export declare function getBankStatementTransactionsText(ofxContent: string): {
24
+ newBankStatementTransactions: string;
25
+ oldBankStatementTransactions: string;
26
+ };
27
+ export declare function getCreditCardStatementTransactionsText(ofxContent: string): {
28
+ newCreditCardStatementTransactions: string;
29
+ oldCreditCardStatementTransactions: string;
30
+ };
31
+ export declare function convertMetaDataToObject(stringList: string[], nativeTypes: boolean): {
32
+ [key: string]: any;
33
+ };
34
+ export declare function getTransactionsSummary(STRTTRN: STRTTRNType[]): {
35
+ credit: number;
36
+ debit: number;
37
+ amountOfCredits: number;
38
+ amountOfDebits: number;
39
+ };
40
+ export {};
@@ -0,0 +1,4 @@
1
+ /// <reference types="node" />
2
+ export declare function bufferToString(data: Buffer): string;
3
+ export declare function fileFromPathToString(pathname: string): Promise<string>;
4
+ export declare function blobToString(blob: Blob): Promise<string>;
@@ -1,11 +1,11 @@
1
- // Ofx-data-extractor v1.2.4 Copyright (c) 2023 Fábio Pereira França
2
- const h=/<\/\w+>/g,m=/<\w+>/g,u="<STMTTRN>",o="</STMTTRN>";function R(n){const t=n.slice(0,4),e=n.slice(4,6),r=n.slice(6,8),s=n.slice(8,10),i=n.slice(10,12),a=n.slice(12,14),[l,p]=n.slice(14).replace("[","").replace("]","").split(":");return{yyyy:t,yy:t.slice(2),y:t,MM:e,M:e,dd:r,d:r,hh:s,h:s,mm:i,m:i,ss:a,s:a,O:l,TZ:p}}function f(n,t){const e=R(n);let r=t;for(const[s,i]of Object.entries(e))r=r.replace(s,i);return r}function T(n){const t=n.replace(/(},})/g,"}}").replace(/(}")/g,'},"').replace(/(},])/g,"}]").replace(/(,})/g,"}").replace(/({")/g,`{
1
+ // Ofx-data-extractor v1.3.0 Copyright (c) 2023 Fábio Pereira França
2
+ const I=/<\/\w+>/g,N=/<\w+>/g,x="<BANKMSGSRSV1>",f="</BANKMSGSRSV1>",E="<CREDITCARDMSGSRSV1>",l="</CREDITCARDMSGSRSV1>",d="<STMTTRN>",c="</STMTTRN>",b=[x,d,E],M=[f,l,c];function O(e){const t=e.slice(0,4),n=e.slice(4,6),r=e.slice(6,8),a=e.slice(8,10),s=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:a,h:a,mm:s,m:s,ss:i,s:i}}function g(e,t){const n=O(e);let r=t;for(const[a,s]of Object.entries(n))r=r.replace(a,s);return r}function T(e){return e.replace(/(\\)/g,"\\\\").replace(I,t=>D(t,!0)).replace(N,t=>w(t,!0)).replace(/(},})/g,"}}").replace(/(}")/g,'},"').replace(/(},])/g,"}]").replace(/(,})/g,"}").replace(/({")/g,`{
3
3
  "`).replace(/(})/g,`
4
4
  }`).replace(/(",")/g,`",
5
5
  "`).replace(/,\s*}/g,`
6
- }`).replace(/(,",)/,",");return t.at(-1)===","?t.slice(0,-1):t}function N(n){const t=n.slice(0,12),e=n.slice(12,19),r=n.slice(19),s={date:t,transactionCode:e,protocol:r};return JSON.stringify(s)}function w(n){return n.startsWith("DT")}function S(n){return n.trim()}function y(n){return n===u?n:n.replace(/[<]/g,`
7
- `).replace(/[>]/g,":{")}function D(n){return n===o?`
8
- ${n}`:"},"}function x(n){const t=n.search(","),e=n.search(".");return t>e?n.replace(/[.]/g,"").replace(/[,]/g,"."):n.replace(/[,]/g,"")}function g(n,t){return n.endsWith("ID")||n.endsWith("NUM")?!1:!isNaN(Number(t))}function d(n){const t=n.indexOf(u),e=n.lastIndexOf(o)+o.length,r=n.substring(t,e),s=new RegExp(u,"g"),i=new RegExp(o,"g"),a=`"STRTTRN":[${r.replace(s,"{").replace(i,"},")}]`;return{oldListText:r,newListText:a}}function E(n,t){const e={};for(const r of n){const[s,i]=r.split(":"),a=s.replace(`
9
- `,"");e[a]=t&&g(s,i)?Number(i):i}return e}function b(n){return n.reduce((t,e)=>e.TRNTYPE.toLocaleLowerCase().startsWith("deb")?(t.amountOfDebits++,t.debit+=Number(e.TRNAMT.replace("-","")),t):(t.amountOfCredits++,t.credit+=Number(e.TRNAMT),t),{credit:0,debit:0,amountOfCredits:0,amountOfDebits:0})}function O(n){return n.toString()}async function _(n){return await new Promise((e,r)=>{import("fs").then(s=>s.readFile(n,(i,a)=>{i?r(i):e(a.toString())}))})}async function M(n){return await new Promise((e,r)=>{if(typeof window<"u"&&window.FileReader){const s=new window.FileReader;s.onload=i=>e(i.target.result),s.onerror=i=>r(i.target.error),s.readAsText(n)}else r(new Error("FileReader is not available in this environment."))})}class c{_data;_config={};constructor(t,e){e&&(this._config=e),this._data=t}static fromBuffer(t){return new c(O(t))}static async fromFilePath(t){const e=await _(t);return new c(e)}static async fromBlob(t){const e=await M(t);return new c(e)}config(t){return this._config=t,this}getHeaders(){const[t]=this._data.split("<OFX>"),e=t.split(`
10
- `),r=i=>!!i.trim().length,s=e.filter(r);return E(s,!!this._config.nativeTypes)}getBankTransferList(){const{newListText:t}=d(this.getPartialJsonData()),e=t.slice(10),r=T(e);return JSON.parse(r)}getPartialJsonData(){const[t,e]=this._data.split("<OFX>"),r="<OFX>"+e,{sanitize:s}=this;return r.replace(h,D).replace(m,y).split(`
11
- `).map(S).filter(Boolean).map(s,this).join("")}sanitizeValue(t,e){let r=e.replace(/[{]/g,"").replace(/(},)/g,"");return t.endsWith("AMT")&&(r=x(r)),w(t)&&(r=this.configDate(r)),t==="FITID"?this.configFinancialInstitutionTransactionId(r):this._config.nativeTypes&&g(t,r)?`${r},`:`"${r}",`}sanitize(t){let e=t;const r=e.slice(0,e.indexOf(":")),s=this.sanitizeValue,i=l=>s.call(this,r,l);return t.match(/{(\w|\W)+/)&&(e=e.replace(/({(\w|\W)+)$/,i)),e.search(/(^\w+:)/)<0?e:e.replace(r+":",`"${r}":`)}configFinancialInstitutionTransactionId(t){const{fitId:e}=this._config;return e==="separated"?N(t):`"${t}",`}configDate(t){const{formatDate:e}=this._config;return e?f(t,e):f(t,"y-M-d")}getTransactionsSummary(){const t=this.getContent(),{DTEND:e,DTSTART:r,STRTTRN:s}=t.OFX.BANKMSGSRSV1.STMTTRNRS.STMTRS.BANKTRANLIST,i=b(s);return{dateStart:r,dateEnd:e,...i}}getContent(){const t=this.getPartialJsonData(),{newListText:e,oldListText:r}=d(t),s=t.replace(r,e);return JSON.parse(`{${T(s)}}`)}toJson(){const t=this.getHeaders(),e=this.getContent();return{...t,...e}}}export{c as Ofx,M as blobToString,O as bufferToString,_ as fileFromPathToString,T as fixJsonProblems,f as formatDate};
6
+ }`).replace(/(,",)/,",").slice(0,-1)}function B(e){const t=e.slice(0,12),n=e.slice(12,19),r=e.slice(19),a={date:t,transactionCode:n,protocol:r};return JSON.stringify(a)}function F(e){return e.startsWith("DT")}function G(e){return e.trim()}function w(e,t=!1){return b.includes(e)&&!t?e:e.replace(/[<]/g,`
7
+ "`).replace(/[>]/g,'":{')}function D(e,t=!1){return M.includes(e)&&!t?`
8
+ ${e}`:"},"}function P({fitId:e,fitValue:t}){return e==="separated"?B(t):`"${t}",`}function k(e){const t=e.search(","),n=e.search(".");return t>n?e.replace(/[.]/g,"").replace(/[,]/g,"."):e.replace(/[,]/g,"")}function _({dateString:e,formatDate:t}){return t?g(e,t):g(e,"y-M-d")}function J(e){let t=e.value.replace(/[{]/g,"").replace(/(},)/g,"");const n=e.field.replace(/['"]/g,"");return n.endsWith("AMT")&&(t=k(t)),F(n)&&(t=_({dateString:t,formatDate:e.formatDate})),n==="FITID"?P({fitId:e.fitId,fitValue:t}):e.nativeTypes&&p(n,t)?`${Number(t)},`:`"${t}",`}function K(e,t){let n=e;const r=n.slice(0,n.indexOf(":")),a=s=>J({field:r,value:s,...t});return e.match(/{(\w|\W)+/)&&(n=n.replace(/({(\w|\W)+)$/,a)),n}function p(e,t){return e.endsWith("ID")||e.endsWith("NUM")?!1:!isNaN(Number(t))}function A(e){const t=e.indexOf(d),n=e.lastIndexOf(c)+c.length,r=e.substring(t,n),a=new RegExp(d,"g"),s=new RegExp(c,"g"),i=`"STRTTRN":[${r.replace(a,"{").replace(s,"},")}]`;return{oldListText:e,newListText:e.replace(r,i)}}function S(e){const t=e.substring(e.indexOf(x),e.indexOf(f)+f.length),n=A(t);return{newBankStatementTransactions:n.newListText,oldBankStatementTransactions:n.oldListText}}function m(e){const t=e.substring(e.indexOf(E),e.indexOf(l)+l.length),n=A(t);return{newCreditCardStatementTransactions:n.newListText,oldCreditCardStatementTransactions:n.oldListText}}function $(e,t){const n={};for(const r of e){const[a,s]=r.split(":"),i=a.replace(`
9
+ `,"");n[i]=t&&p(a,s)?Number(s):s}return n}function z(e){return e.reduce((t,n)=>n.TRNTYPE.toLocaleLowerCase().startsWith("deb")?(t.amountOfDebits++,t.debit+=Number(n.TRNAMT.replace("-","")),t):(t.amountOfCredits++,t.credit+=Number(n.TRNAMT),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 K(t,this.internConfig)}getPartialJsonData(t){const[n,r]=t.split("<OFX>"),a="<OFX>"+r,{sanitizeRow:s}=this;return a.replace(I,i=>D(i)).replace(N,i=>w(i)).split(`
10
+ `).map(G).filter(Boolean).map(s,this).join("")}}function R(e){return e.toString()}async function h(e){return await new Promise((n,r)=>{import("fs").then(a=>a.readFile(e,(s,i)=>{s?r(s):n(i.toString())}))})}async function C(e){return await new Promise((n,r)=>{if(typeof window<"u"&&window.FileReader){const a=new window.FileReader;a.onload=s=>n(s.target.result),a.onerror=s=>r(s.target.error),a.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(R(t))}async fromFilePath(t){return new o(await h(t))}async fromBlob(t){return new o(await C(t))}static fromString(t){return new o(t)}static fromBuffer(t){return new o(R(t))}static async fromFilePath(t){return new o(await h(t))}static async fromBlob(t){return new o(await C(t))}}class W{configInstance={}}class y extends W{setConfig(t){this.configInstance=t}getBankTransferList(t){const{newBankStatementTransactions:n}=S(this.configInstance.getPartialJsonData(t));return JSON.parse(`{${T(n)}}`)?.BANKMSGSRSV1?.STMTTRNRS?.STMTRS?.BANKTRANLIST?.STRTTRN}getCreditCardTransferList(t){const{newCreditCardStatementTransactions:n}=m(this.configInstance.getPartialJsonData(t));return JSON.parse(`{${T(n)}}`)?.CREDITCARDMSGSRSV1?.CCSTMTTRNRS?.CCSTMTRS?.BANKTRANLIST?.STRTTRN}getTransactionsSummary(t){const n=this.getContent(t),{DTEND:r,DTSTART:a,STRTTRN:s}=n.OFX.BANKMSGSRSV1.STMTTRNRS.STMTRS.BANKTRANLIST,i=z(s);return{dateStart:a,dateEnd:r,...i}}getContent(t){const n=this.configInstance.getPartialJsonData(t),{newBankStatementTransactions:r,oldBankStatementTransactions:a}=S(n),{newCreditCardStatementTransactions:s,oldCreditCardStatementTransactions:i}=m(n),L=n.replace(i,s).replace(a,r);return JSON.parse(`{${T(L)}}`)}}class j{customExtractor;customExtractorInstance;dataReaderInstance=new o("");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 V(t)),this}getHeaders(){const[t]=this.dataReaderInstance.getData().split("<OFX>"),n=t.split(`
11
+ `),r=s=>!!s.trim().length,a=n.filter(r);return $(a,!!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 u{extractor;constructor(t,n){this.extractor=new j(new y),this.extractor.data(new o(t)),this.extractor.config(n||{})}static fromBuffer(t){return new u(o.fromBuffer(t).getData())}static async fromFilePath(t){const n=await o.fromFilePath(t);return new u(n.getData())}static async fromBlob(t){const n=await o.fromBlob(t);return new u(n.getData())}config(t){return this.extractor.config(t),this}getHeaders(){return this.extractor.getHeaders()}getBankTransferList(){return this.extractor.getBankTransferList()}getTransactionsSummary(){return this.extractor.getTransactionsSummary()}getContent(){return this.extractor.getContent()}toJson(){return this.extractor.toJson()}}export{j as Extractor,u as Ofx,y as OfxExtractor,o as Reader,C as blobToString,R as bufferToString,h as fileFromPathToString,T as fixJsonProblems,g as formatDate};
@@ -0,0 +1,19 @@
1
+ import type { ExtractorConfig, MetaData, TransactionsSummary } from '../@types/common';
2
+ import { IExtractor } from '../interfaces/extractor.interface';
3
+ import { CustomExtractor } from '../interfaces/custom-extractor.interface';
4
+ import { Reader } from './reader';
5
+ import { OfxResponse, OfxStructure, STRTTRN } from '../@types/ofx';
6
+ export declare class Extractor<T = any> implements IExtractor<T> {
7
+ private readonly customExtractor?;
8
+ private customExtractorInstance;
9
+ private dataReaderInstance;
10
+ constructor(customExtractor?: CustomExtractor | undefined);
11
+ data(readData: Reader): this;
12
+ config(config: ExtractorConfig): this;
13
+ getHeaders(): MetaData;
14
+ getBankTransferList(): STRTTRN[];
15
+ getCreditCardTransferList(): STRTTRN[];
16
+ getTransactionsSummary(): TransactionsSummary;
17
+ getContent(): OfxStructure;
18
+ toJson(): OfxResponse;
19
+ }
@@ -0,0 +1,11 @@
1
+ import { OfxStructure } from '../@types/ofx';
2
+ import { CustomExtractor } from '../interfaces/custom-extractor.interface';
3
+ import { Config } from '../common/config';
4
+ import { TransactionsSummary } from '../@types/common';
5
+ export declare class OfxExtractor extends CustomExtractor {
6
+ setConfig(config: Config): void;
7
+ getBankTransferList(data: string): any;
8
+ getCreditCardTransferList(data: string): any;
9
+ getTransactionsSummary(data: string): TransactionsSummary;
10
+ getContent(data: string): OfxStructure;
11
+ }
@@ -0,0 +1,15 @@
1
+ /// <reference types="node" />
2
+ export declare class Reader {
3
+ private readonly data?;
4
+ private dataRead;
5
+ constructor(data?: string | undefined);
6
+ getData(): string;
7
+ fromString(data: string): Reader;
8
+ fromBuffer(data: Buffer): Reader;
9
+ fromFilePath(pathname: string): Promise<Reader>;
10
+ fromBlob(blob: Blob): Promise<Reader>;
11
+ static fromString(data: string): Reader;
12
+ static fromBuffer(data: Buffer): Reader;
13
+ static fromFilePath(pathname: string): Promise<Reader>;
14
+ static fromBlob(blob: Blob): Promise<Reader>;
15
+ }
package/dist/index.d.ts CHANGED
@@ -1,3 +1,11 @@
1
- export { Ofx } from './main';
2
- export { formatDate, fixJsonProblems, blobToString, bufferToString, fileFromPathToString, } from './helpers';
3
- export type { OfxResponse, OFXMetaData, OfxStructure, BankTransferList, } from './types';
1
+ export { Ofx } from './older-implementation/main';
2
+ export { blobToString, bufferToString, fileFromPathToString, } from './common/reader';
3
+ export { fixJsonProblems } from './common/parse';
4
+ export { formatDate } from './common/date';
5
+ export type { IExtractor } from './interfaces/extractor.interface';
6
+ export type { CustomExtractor } from './interfaces/custom-extractor.interface';
7
+ export type { OfxResponse, OfxStructure, BankTransferList } from './@types/ofx';
8
+ export { Reader } from './implementations/reader';
9
+ export { OfxExtractor } from './implementations/ofx-extractor';
10
+ export { Extractor } from './implementations/extractor';
11
+ export type { MetaData, ExtractorConfig, DateResponse } from './@types/common';
@@ -0,0 +1,10 @@
1
+ import { Config } from 'src/common/config';
2
+ import { TransactionsSummary } from '../@types/common';
3
+ export declare abstract class CustomExtractor {
4
+ configInstance: Config;
5
+ abstract setConfig(config: Config): void;
6
+ abstract getBankTransferList(data: string): any;
7
+ abstract getCreditCardTransferList(data: string): any;
8
+ abstract getTransactionsSummary(data: string): TransactionsSummary;
9
+ abstract getContent(data: string): object;
10
+ }
@@ -0,0 +1,11 @@
1
+ import { OfxResponse, OfxStructure, STRTTRN } from '../@types/ofx';
2
+ import { ExtractorConfig, MetaData, TransactionsSummary } from 'src/@types/common';
3
+ export interface IExtractor<T> {
4
+ config(config: ExtractorConfig): this;
5
+ getHeaders(): MetaData;
6
+ getBankTransferList(): STRTTRN[];
7
+ getCreditCardTransferList(): STRTTRN[];
8
+ getTransactionsSummary(): TransactionsSummary;
9
+ getContent(): OfxStructure;
10
+ toJson(): OfxResponse;
11
+ }
@@ -0,0 +1,16 @@
1
+ /// <reference types="node" />
2
+ import { MetaData } from '../@types/common';
3
+ import { OfxResponse, OfxStructure, STRTTRN, OfxConfig } from '../@types/ofx';
4
+ export declare class Ofx {
5
+ private extractor;
6
+ constructor(data: string, config?: OfxConfig);
7
+ static fromBuffer(data: Buffer): Ofx;
8
+ static fromFilePath(pathname: string): Promise<Ofx>;
9
+ static fromBlob(blob: Blob): Promise<Ofx>;
10
+ config(config: OfxConfig): this;
11
+ getHeaders(): MetaData;
12
+ getBankTransferList(): STRTTRN[];
13
+ getTransactionsSummary(): import("../@types/common").TransactionsSummary;
14
+ getContent(): OfxStructure;
15
+ toJson(): OfxResponse;
16
+ }
@@ -1,11 +1,11 @@
1
- // Ofx-data-extractor v1.2.4 Copyright (c) 2023 Fábio Pereira França
2
- (function(o,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(o=typeof globalThis<"u"?globalThis:o||self,c(o.ofx={}))})(this,function(o){"use strict";const c=/<\/\w+>/g,S=/<\w+>/g,u="<STMTTRN>",f="</STMTTRN>";function y(n){const t=n.slice(0,4),e=n.slice(4,6),s=n.slice(6,8),r=n.slice(8,10),i=n.slice(10,12),a=n.slice(12,14),[g,M]=n.slice(14).replace("[","").replace("]","").split(":");return{yyyy:t,yy:t.slice(2),y:t,MM:e,M:e,dd:s,d:s,hh:r,h:r,mm:i,m:i,ss:a,s:a,O:g,TZ:M}}function T(n,t){const e=y(n);let s=t;for(const[r,i]of Object.entries(e))s=s.replace(r,i);return s}function d(n){const t=n.replace(/(},})/g,"}}").replace(/(}")/g,'},"').replace(/(},])/g,"}]").replace(/(,})/g,"}").replace(/({")/g,`{
1
+ // Ofx-data-extractor v1.3.0 Copyright (c) 2023 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,E="<BANKMSGSRSV1>",d="</BANKMSGSRSV1>",x="<CREDITCARDMSGSRSV1>",g="</CREDITCARDMSGSRSV1>",S="<STMTTRN>",T="</STMTTRN>",O=[E,S,x],M=[d,g,T];function B(e){const t=e.slice(0,4),n=e.slice(4,6),r=e.slice(6,8),a=e.slice(8,10),s=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:a,h:a,mm:s,m:s,ss:i,s:i}}function m(e,t){const n=B(e);let r=t;for(const[a,s]of Object.entries(n))r=r.replace(a,s);return r}function l(e){return e.replace(/(\\)/g,"\\\\").replace(u,t=>D(t,!0)).replace(N,t=>w(t,!0)).replace(/(},})/g,"}}").replace(/(}")/g,'},"').replace(/(},])/g,"}]").replace(/(,})/g,"}").replace(/({")/g,`{
3
3
  "`).replace(/(})/g,`
4
4
  }`).replace(/(",")/g,`",
5
5
  "`).replace(/,\s*}/g,`
6
- }`).replace(/(,",)/,",");return t.at(-1)===","?t.slice(0,-1):t}function w(n){const t=n.slice(0,12),e=n.slice(12,19),s=n.slice(19),r={date:t,transactionCode:e,protocol:s};return JSON.stringify(r)}function b(n){return n.startsWith("DT")}function D(n){return n.trim()}function x(n){return n===u?n:n.replace(/[<]/g,`
7
- `).replace(/[>]/g,":{")}function E(n){return n===f?`
8
- ${n}`:"},"}function O(n){const t=n.search(","),e=n.search(".");return t>e?n.replace(/[.]/g,"").replace(/[,]/g,"."):n.replace(/[,]/g,"")}function p(n,t){return n.endsWith("ID")||n.endsWith("NUM")?!1:!isNaN(Number(t))}function h(n){const t=n.indexOf(u),e=n.lastIndexOf(f)+f.length,s=n.substring(t,e),r=new RegExp(u,"g"),i=new RegExp(f,"g"),a=`"STRTTRN":[${s.replace(r,"{").replace(i,"},")}]`;return{oldListText:s,newListText:a}}function _(n,t){const e={};for(const s of n){const[r,i]=s.split(":"),a=r.replace(`
9
- `,"");e[a]=t&&p(r,i)?Number(i):i}return e}function F(n){return n.reduce((t,e)=>e.TRNTYPE.toLocaleLowerCase().startsWith("deb")?(t.amountOfDebits++,t.debit+=Number(e.TRNAMT.replace("-","")),t):(t.amountOfCredits++,t.credit+=Number(e.TRNAMT),t),{credit:0,debit:0,amountOfCredits:0,amountOfDebits:0})}function m(n){return n.toString()}async function R(n){return await new Promise((e,s)=>{import("fs").then(r=>r.readFile(n,(i,a)=>{i?s(i):e(a.toString())}))})}async function N(n){return await new Promise((e,s)=>{if(typeof window<"u"&&window.FileReader){const r=new window.FileReader;r.onload=i=>e(i.target.result),r.onerror=i=>s(i.target.error),r.readAsText(n)}else s(new Error("FileReader is not available in this environment."))})}class l{_data;_config={};constructor(t,e){e&&(this._config=e),this._data=t}static fromBuffer(t){return new l(m(t))}static async fromFilePath(t){const e=await R(t);return new l(e)}static async fromBlob(t){const e=await N(t);return new l(e)}config(t){return this._config=t,this}getHeaders(){const[t]=this._data.split("<OFX>"),e=t.split(`
10
- `),s=i=>!!i.trim().length,r=e.filter(s);return _(r,!!this._config.nativeTypes)}getBankTransferList(){const{newListText:t}=h(this.getPartialJsonData()),e=t.slice(10),s=d(e);return JSON.parse(s)}getPartialJsonData(){const[t,e]=this._data.split("<OFX>"),s="<OFX>"+e,{sanitize:r}=this;return s.replace(c,E).replace(S,x).split(`
11
- `).map(D).filter(Boolean).map(r,this).join("")}sanitizeValue(t,e){let s=e.replace(/[{]/g,"").replace(/(},)/g,"");return t.endsWith("AMT")&&(s=O(s)),b(t)&&(s=this.configDate(s)),t==="FITID"?this.configFinancialInstitutionTransactionId(s):this._config.nativeTypes&&p(t,s)?`${s},`:`"${s}",`}sanitize(t){let e=t;const s=e.slice(0,e.indexOf(":")),r=this.sanitizeValue,i=g=>r.call(this,s,g);return t.match(/{(\w|\W)+/)&&(e=e.replace(/({(\w|\W)+)$/,i)),e.search(/(^\w+:)/)<0?e:e.replace(s+":",`"${s}":`)}configFinancialInstitutionTransactionId(t){const{fitId:e}=this._config;return e==="separated"?w(t):`"${t}",`}configDate(t){const{formatDate:e}=this._config;return e?T(t,e):T(t,"y-M-d")}getTransactionsSummary(){const t=this.getContent(),{DTEND:e,DTSTART:s,STRTTRN:r}=t.OFX.BANKMSGSRSV1.STMTTRNRS.STMTRS.BANKTRANLIST,i=F(r);return{dateStart:s,dateEnd:e,...i}}getContent(){const t=this.getPartialJsonData(),{newListText:e,oldListText:s}=h(t),r=t.replace(s,e);return JSON.parse(`{${d(r)}}`)}toJson(){const t=this.getHeaders(),e=this.getContent();return{...t,...e}}}o.Ofx=l,o.blobToString=N,o.bufferToString=m,o.fileFromPathToString=R,o.fixJsonProblems=d,o.formatDate=T});
6
+ }`).replace(/(,",)/,",").slice(0,-1)}function F(e){const t=e.slice(0,12),n=e.slice(12,19),r=e.slice(19),a={date:t,transactionCode:n,protocol:r};return JSON.stringify(a)}function P(e){return e.startsWith("DT")}function G(e){return e.trim()}function w(e,t=!1){return O.includes(e)&&!t?e:e.replace(/[<]/g,`
7
+ "`).replace(/[>]/g,'":{')}function D(e,t=!1){return M.includes(e)&&!t?`
8
+ ${e}`:"},"}function k({fitId:e,fitValue:t}){return e==="separated"?F(t):`"${t}",`}function _(e){const t=e.search(","),n=e.search(".");return t>n?e.replace(/[.]/g,"").replace(/[,]/g,"."):e.replace(/[,]/g,"")}function J({dateString:e,formatDate:t}){return t?m(e,t):m(e,"y-M-d")}function K(e){let t=e.value.replace(/[{]/g,"").replace(/(},)/g,"");const n=e.field.replace(/['"]/g,"");return n.endsWith("AMT")&&(t=_(t)),P(n)&&(t=J({dateString:t,formatDate:e.formatDate})),n==="FITID"?k({fitId:e.fitId,fitValue:t}):e.nativeTypes&&p(n,t)?`${Number(t)},`:`"${t}",`}function $(e,t){let n=e;const r=n.slice(0,n.indexOf(":")),a=s=>K({field:r,value:s,...t});return e.match(/{(\w|\W)+/)&&(n=n.replace(/({(\w|\W)+)$/,a)),n}function p(e,t){return e.endsWith("ID")||e.endsWith("NUM")?!1:!isNaN(Number(t))}function b(e){const t=e.indexOf(S),n=e.lastIndexOf(T)+T.length,r=e.substring(t,n),a=new RegExp(S,"g"),s=new RegExp(T,"g"),i=`"STRTTRN":[${r.replace(a,"{").replace(s,"},")}]`;return{oldListText:e,newListText:e.replace(r,i)}}function y(e){const t=e.substring(e.indexOf(E),e.indexOf(d)+d.length),n=b(t);return{newBankStatementTransactions:n.newListText,oldBankStatementTransactions:n.oldListText}}function A(e){const t=e.substring(e.indexOf(x),e.indexOf(g)+g.length),n=b(t);return{newCreditCardStatementTransactions:n.newListText,oldCreditCardStatementTransactions:n.oldListText}}function j(e,t){const n={};for(const r of e){const[a,s]=r.split(":"),i=a.replace(`
9
+ `,"");n[i]=t&&p(a,s)?Number(s):s}return n}function z(e){return e.reduce((t,n)=>n.TRNTYPE.toLocaleLowerCase().startsWith("deb")?(t.amountOfDebits++,t.debit+=Number(n.TRNAMT.replace("-","")),t):(t.amountOfCredits++,t.credit+=Number(n.TRNAMT),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 $(t,this.internConfig)}getPartialJsonData(t){const[n,r]=t.split("<OFX>"),a="<OFX>"+r,{sanitizeRow:s}=this;return a.replace(u,i=>D(i)).replace(N,i=>w(i)).split(`
10
+ `).map(G).filter(Boolean).map(s,this).join("")}}function R(e){return e.toString()}async function h(e){return await new Promise((n,r)=>{import("fs").then(a=>a.readFile(e,(s,i)=>{s?r(s):n(i.toString())}))})}async function C(e){return await new Promise((n,r)=>{if(typeof window<"u"&&window.FileReader){const a=new window.FileReader;a.onload=s=>n(s.target.result),a.onerror=s=>r(s.target.error),a.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(R(t))}async fromFilePath(t){return new o(await h(t))}async fromBlob(t){return new o(await C(t))}static fromString(t){return new o(t)}static fromBuffer(t){return new o(R(t))}static async fromFilePath(t){return new o(await h(t))}static async fromBlob(t){return new o(await C(t))}}class W{configInstance={}}class I extends W{setConfig(t){this.configInstance=t}getBankTransferList(t){const{newBankStatementTransactions:n}=y(this.configInstance.getPartialJsonData(t));return JSON.parse(`{${l(n)}}`)?.BANKMSGSRSV1?.STMTTRNRS?.STMTRS?.BANKTRANLIST?.STRTTRN}getCreditCardTransferList(t){const{newCreditCardStatementTransactions:n}=A(this.configInstance.getPartialJsonData(t));return JSON.parse(`{${l(n)}}`)?.CREDITCARDMSGSRSV1?.CCSTMTTRNRS?.CCSTMTRS?.BANKTRANLIST?.STRTTRN}getTransactionsSummary(t){const n=this.getContent(t),{DTEND:r,DTSTART:a,STRTTRN:s}=n.OFX.BANKMSGSRSV1.STMTTRNRS.STMTRS.BANKTRANLIST,i=z(s);return{dateStart:a,dateEnd:r,...i}}getContent(t){const n=this.configInstance.getPartialJsonData(t),{newBankStatementTransactions:r,oldBankStatementTransactions:a}=y(n),{newCreditCardStatementTransactions:s,oldCreditCardStatementTransactions:i}=A(n),X=n.replace(i,s).replace(a,r);return JSON.parse(`{${l(X)}}`)}}class L{customExtractor;customExtractorInstance;dataReaderInstance=new o("");constructor(t){this.customExtractor=t,this.customExtractorInstance=t||new I,this.config({})}data(t){return this.dataReaderInstance=t,this}config(t){return this.customExtractorInstance.setConfig(new V(t)),this}getHeaders(){const[t]=this.dataReaderInstance.getData().split("<OFX>"),n=t.split(`
11
+ `),r=s=>!!s.trim().length,a=n.filter(r);return j(a,!!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 f{extractor;constructor(t,n){this.extractor=new L(new I),this.extractor.data(new o(t)),this.extractor.config(n||{})}static fromBuffer(t){return new f(o.fromBuffer(t).getData())}static async fromFilePath(t){const n=await o.fromFilePath(t);return new f(n.getData())}static async fromBlob(t){const n=await o.fromBlob(t);return new f(n.getData())}config(t){return this.extractor.config(t),this}getHeaders(){return this.extractor.getHeaders()}getBankTransferList(){return this.extractor.getBankTransferList()}getTransactionsSummary(){return this.extractor.getTransactionsSummary()}getContent(){return this.extractor.getContent()}toJson(){return this.extractor.toJson()}}c.Extractor=L,c.Ofx=f,c.OfxExtractor=I,c.Reader=o,c.blobToString=C,c.bufferToString=R,c.fileFromPathToString=h,c.fixJsonProblems=l,c.formatDate=m});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ofx-data-extractor",
3
- "version": "1.2.4",
3
+ "version": "1.3.0",
4
4
  "keywords": [
5
5
  "ofx",
6
6
  "financial",
package/dist/config.d.ts DELETED
@@ -1,4 +0,0 @@
1
- export declare const ELEMENT_CLOSURE_REGEX: RegExp;
2
- export declare const ELEMENT_OPENING_REGEX: RegExp;
3
- export declare const START_TEXT_BANK_TRANSFER = "<STMTTRN>";
4
- export declare const END_TEXT_BANK_TRANSFER = "</STMTTRN>";
package/dist/helpers.d.ts DELETED
@@ -1,27 +0,0 @@
1
- /// <reference types="node" />
2
- import { STRTTRN as STRTTRNType } from './types';
3
- export declare function formatDate(date: string, format: string): string;
4
- export declare function fixJsonProblems(content: string): string;
5
- export declare function extractFinancialInstitutionTransactionId(fitid: string): string;
6
- export declare function isDateField(field: string): boolean;
7
- export declare function trim(str: string): string;
8
- export declare function objectStartReplacer(param: string): string;
9
- export declare function objectEndReplacer(param: string): string;
10
- export declare function sanitizeCurrency(value: string): string;
11
- export declare function isValidNumberToConvert(field: string, value: string): boolean;
12
- export declare function getBankTransferListText(ofxContent: string): {
13
- oldListText: string;
14
- newListText: string;
15
- };
16
- export declare function convertMetaDataToObject(stringList: string[], nativeTypes: boolean): {
17
- [key: string]: any;
18
- };
19
- export declare function getTransactionsSummary(STRTTRN: STRTTRNType[]): {
20
- credit: number;
21
- debit: number;
22
- amountOfCredits: number;
23
- amountOfDebits: number;
24
- };
25
- export declare function bufferToString(data: Buffer): string;
26
- export declare function fileFromPathToString(pathname: string): Promise<string>;
27
- export declare function blobToString(blob: Blob): Promise<string>;
package/dist/main.d.ts DELETED
@@ -1,28 +0,0 @@
1
- /// <reference types="node" />
2
- import { OfxConfig, OFXMetaData, OfxResponse, OfxStructure, STRTTRN } from './types';
3
- export declare class Ofx {
4
- private _data;
5
- private _config;
6
- constructor(data: string, config?: OfxConfig);
7
- static fromBuffer(data: Buffer): Ofx;
8
- static fromFilePath(pathname: string): Promise<Ofx>;
9
- static fromBlob(blob: Blob): Promise<Ofx>;
10
- config(config: OfxConfig): this;
11
- getHeaders(): OFXMetaData;
12
- getBankTransferList(): STRTTRN[];
13
- private getPartialJsonData;
14
- private sanitizeValue;
15
- private sanitize;
16
- private configFinancialInstitutionTransactionId;
17
- private configDate;
18
- getTransactionsSummary(): {
19
- credit: number;
20
- debit: number;
21
- amountOfCredits: number;
22
- amountOfDebits: number;
23
- dateStart: import("./types").DateResponse;
24
- dateEnd: import("./types").DateResponse;
25
- };
26
- getContent(): OfxStructure;
27
- toJson(): OfxResponse;
28
- }
package/dist/types.d.ts DELETED
@@ -1,114 +0,0 @@
1
- export type OFXMetaData = {
2
- OFXHEADER: string;
3
- DATA: string;
4
- VERSION: string;
5
- SECURITY: string;
6
- ENCODING: string;
7
- CHARSET: string;
8
- COMPRESSION: string;
9
- OLDFILEUID: string;
10
- NEWFILEUID: string;
11
- };
12
- export type DateResponse = {
13
- datetime: string | null;
14
- date: string | null;
15
- time: string | null;
16
- offset: string | null;
17
- timezone: string | null;
18
- };
19
- /**
20
- * separated - returns the separate transaction id:
21
- * "date": string,
22
- * "transactionCode": string,
23
- * "protocol": string
24
- */
25
- type ConfigFitId = 'normal' | 'separated';
26
- export type ConfigDate = {
27
- /**
28
- * @description supported keys:
29
- * yy => year -> 2 digits,
30
- * yyyy or y => year,
31
- * MM or M => month,
32
- * dd or d => day,
33
- * hh or h => hour,
34
- * mm or m => minute,
35
- * ss or s => second,
36
- * O => offset,
37
- * TZ => timezone
38
- * @example format: 'y-M-d h:m:s'
39
- * @returns '2022-02-21 09:00:00'
40
- */
41
- formatDate?: string;
42
- };
43
- type MapKeys<T> = {
44
- [Property in keyof T]?: string;
45
- };
46
- type KeysJson = MapKeys<Status | BankAccountFrom | STRTTRN | BankTransferList | LedGerBal | FINANCIAL_INSTITUTION | OfxStructure>;
47
- export type OfxConfig = ConfigDate & {
48
- fitId?: ConfigFitId;
49
- nativeTypes?: boolean;
50
- formatJson?: MapKeys<KeysJson>;
51
- };
52
- export type Status = {
53
- CODE: string;
54
- SEVERITY: string;
55
- };
56
- export type BankAccountFrom = {
57
- BANKID: string;
58
- ACCTID: string;
59
- ACCTT: string;
60
- };
61
- type TransferType = string;
62
- export type STRTTRN = {
63
- TRNTYPE: TransferType;
64
- DTPOSTED: DateResponse;
65
- TRNAMT: string;
66
- FITID: string | {
67
- date: string;
68
- protocol: string;
69
- transactionCode: string;
70
- };
71
- CHECKNUM: string;
72
- MEMO: string;
73
- };
74
- export type BankTransferList = {
75
- DTSTART: DateResponse;
76
- DTEND: DateResponse;
77
- STRTTRN: STRTTRN[];
78
- };
79
- export type LedGerBal = {
80
- BALAMT: string;
81
- DTASOF: DateResponse;
82
- };
83
- export type FINANCIAL_INSTITUTION = {
84
- ORG: string;
85
- FID: string;
86
- };
87
- export type OfxStructure = {
88
- OFX: {
89
- SIGNONMSGSRSV1: {
90
- SONRS: {
91
- STATUS: Status;
92
- DTSERVER: DateResponse;
93
- LANGUAGE: string;
94
- DTACCTUP: DateResponse;
95
- FI: FINANCIAL_INSTITUTION;
96
- };
97
- };
98
- BANKMSGSRSV1: {
99
- STMTTRNRS: {
100
- TRNUID: number;
101
- STATUS: Status;
102
- STMTRS: {
103
- CURDEF: string;
104
- BANKACCTFROM: BankAccountFrom;
105
- BANKTRANLIST: BankTransferList;
106
- LEDGERBAL: LedGerBal;
107
- MKTGINFO: string;
108
- };
109
- };
110
- };
111
- };
112
- };
113
- export type OfxResponse = OFXMetaData & OfxStructure;
114
- export {};