@f-o-t/ofx 1.2.0 → 1.2.1
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/dist/index.d.ts +65 -1
- package/dist/index.js +209 -1
- package/package.json +5 -2
package/dist/index.d.ts
CHANGED
|
@@ -59,4 +59,68 @@ interface BalanceInfo {
|
|
|
59
59
|
}
|
|
60
60
|
declare function getBalance(document: OFXDocument): BalanceInfo[];
|
|
61
61
|
declare function getSignOnInfo(document: OFXDocument): OFXSignOnResponse;
|
|
62
|
-
|
|
62
|
+
declare function formatOfxDate(date: Date, timezone?: {
|
|
63
|
+
offset: number;
|
|
64
|
+
name: string;
|
|
65
|
+
}): string;
|
|
66
|
+
interface GenerateHeaderOptions {
|
|
67
|
+
version?: string;
|
|
68
|
+
encoding?: string;
|
|
69
|
+
charset?: string;
|
|
70
|
+
}
|
|
71
|
+
declare function generateHeader(options?: GenerateHeaderOptions): string;
|
|
72
|
+
interface GenerateTransactionInput {
|
|
73
|
+
type: OFXTransactionType;
|
|
74
|
+
datePosted: Date;
|
|
75
|
+
amount: number;
|
|
76
|
+
fitId: string;
|
|
77
|
+
name?: string;
|
|
78
|
+
memo?: string;
|
|
79
|
+
checkNum?: string;
|
|
80
|
+
refNum?: string;
|
|
81
|
+
}
|
|
82
|
+
interface GenerateBankStatementOptions {
|
|
83
|
+
bankId: string;
|
|
84
|
+
accountId: string;
|
|
85
|
+
accountType: OFXAccountType;
|
|
86
|
+
currency: string;
|
|
87
|
+
startDate: Date;
|
|
88
|
+
endDate: Date;
|
|
89
|
+
transactions: GenerateTransactionInput[];
|
|
90
|
+
ledgerBalance?: {
|
|
91
|
+
amount: number;
|
|
92
|
+
asOfDate: Date;
|
|
93
|
+
};
|
|
94
|
+
availableBalance?: {
|
|
95
|
+
amount: number;
|
|
96
|
+
asOfDate: Date;
|
|
97
|
+
};
|
|
98
|
+
financialInstitution?: {
|
|
99
|
+
org?: string;
|
|
100
|
+
fid?: string;
|
|
101
|
+
};
|
|
102
|
+
language?: string;
|
|
103
|
+
}
|
|
104
|
+
declare function generateBankStatement(options: GenerateBankStatementOptions): string;
|
|
105
|
+
interface GenerateCreditCardStatementOptions {
|
|
106
|
+
accountId: string;
|
|
107
|
+
currency: string;
|
|
108
|
+
startDate: Date;
|
|
109
|
+
endDate: Date;
|
|
110
|
+
transactions: GenerateTransactionInput[];
|
|
111
|
+
ledgerBalance?: {
|
|
112
|
+
amount: number;
|
|
113
|
+
asOfDate: Date;
|
|
114
|
+
};
|
|
115
|
+
availableBalance?: {
|
|
116
|
+
amount: number;
|
|
117
|
+
asOfDate: Date;
|
|
118
|
+
};
|
|
119
|
+
financialInstitution?: {
|
|
120
|
+
org?: string;
|
|
121
|
+
fid?: string;
|
|
122
|
+
};
|
|
123
|
+
language?: string;
|
|
124
|
+
}
|
|
125
|
+
declare function generateCreditCardStatement(options: GenerateCreditCardStatementOptions): string;
|
|
126
|
+
export { schemas, parseOrThrow, parse, getTransactions, getSignOnInfo, getBalance, getAccountInfo, generateHeader, generateCreditCardStatement, generateBankStatement, formatOfxDate, ParseResult, OFXTransactionType, OFXTransactionList, OFXTransaction, OFXStatus, OFXSignOnResponse, OFXSignOnMessageSetResponse, OFXResponse, OFXHeader, OFXFinancialInstitution, OFXDocument, OFXDate, OFXCreditCardStatementTransactionResponse, OFXCreditCardStatementResponse, OFXCreditCardMessageSetResponse, OFXCreditCardAccount, OFXBankStatementTransactionResponse, OFXBankStatementResponse, OFXBankMessageSetResponse, OFXBankAccount, OFXBalance, OFXAccountType, GenerateTransactionInput, GenerateHeaderOptions, GenerateCreditCardStatementOptions, GenerateBankStatementOptions, BalanceInfo };
|
package/dist/index.js
CHANGED
|
@@ -358,6 +358,210 @@ function getBalance(document) {
|
|
|
358
358
|
function getSignOnInfo(document) {
|
|
359
359
|
return document.OFX.SIGNONMSGSRSV1.SONRS;
|
|
360
360
|
}
|
|
361
|
+
var pad = (n, width = 2) => n.toString().padStart(width, "0");
|
|
362
|
+
function formatOfxDate(date, timezone) {
|
|
363
|
+
const tz = timezone ?? { name: "GMT", offset: 0 };
|
|
364
|
+
const offsetMs = tz.offset * 60 * 60 * 1000;
|
|
365
|
+
const adjustedDate = new Date(date.getTime() + offsetMs);
|
|
366
|
+
const year = adjustedDate.getUTCFullYear();
|
|
367
|
+
const month = pad(adjustedDate.getUTCMonth() + 1);
|
|
368
|
+
const day = pad(adjustedDate.getUTCDate());
|
|
369
|
+
const hour = pad(adjustedDate.getUTCHours());
|
|
370
|
+
const minute = pad(adjustedDate.getUTCMinutes());
|
|
371
|
+
const second = pad(adjustedDate.getUTCSeconds());
|
|
372
|
+
const sign = tz.offset >= 0 ? "+" : "";
|
|
373
|
+
return `${year}${month}${day}${hour}${minute}${second}[${sign}${tz.offset}:${tz.name}]`;
|
|
374
|
+
}
|
|
375
|
+
function escapeOfxText(text) {
|
|
376
|
+
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
377
|
+
}
|
|
378
|
+
function formatAmount(amount) {
|
|
379
|
+
return amount.toFixed(2);
|
|
380
|
+
}
|
|
381
|
+
function generateHeader(options) {
|
|
382
|
+
const version = options?.version ?? "100";
|
|
383
|
+
const encoding = options?.encoding ?? "USASCII";
|
|
384
|
+
const charset = options?.charset ?? "1252";
|
|
385
|
+
return [
|
|
386
|
+
"OFXHEADER:100",
|
|
387
|
+
"DATA:OFXSGML",
|
|
388
|
+
`VERSION:${version}`,
|
|
389
|
+
"SECURITY:NONE",
|
|
390
|
+
`ENCODING:${encoding}`,
|
|
391
|
+
`CHARSET:${charset}`,
|
|
392
|
+
"COMPRESSION:NONE",
|
|
393
|
+
"OLDFILEUID:NONE",
|
|
394
|
+
"NEWFILEUID:NONE",
|
|
395
|
+
""
|
|
396
|
+
].join(`
|
|
397
|
+
`);
|
|
398
|
+
}
|
|
399
|
+
function generateTransaction(trn) {
|
|
400
|
+
const lines = [
|
|
401
|
+
"<STMTTRN>",
|
|
402
|
+
`<TRNTYPE>${trn.type}`,
|
|
403
|
+
`<DTPOSTED>${formatOfxDate(trn.datePosted)}`,
|
|
404
|
+
`<TRNAMT>${formatAmount(trn.amount)}`,
|
|
405
|
+
`<FITID>${escapeOfxText(trn.fitId)}`
|
|
406
|
+
];
|
|
407
|
+
if (trn.name) {
|
|
408
|
+
lines.push(`<NAME>${escapeOfxText(trn.name)}`);
|
|
409
|
+
}
|
|
410
|
+
if (trn.memo) {
|
|
411
|
+
lines.push(`<MEMO>${escapeOfxText(trn.memo)}`);
|
|
412
|
+
}
|
|
413
|
+
if (trn.checkNum) {
|
|
414
|
+
lines.push(`<CHECKNUM>${escapeOfxText(trn.checkNum)}`);
|
|
415
|
+
}
|
|
416
|
+
if (trn.refNum) {
|
|
417
|
+
lines.push(`<REFNUM>${escapeOfxText(trn.refNum)}`);
|
|
418
|
+
}
|
|
419
|
+
lines.push("</STMTTRN>");
|
|
420
|
+
return lines.join(`
|
|
421
|
+
`);
|
|
422
|
+
}
|
|
423
|
+
function generateBankStatement(options) {
|
|
424
|
+
const header = generateHeader();
|
|
425
|
+
const serverDate = formatOfxDate(new Date);
|
|
426
|
+
const language = options.language ?? "POR";
|
|
427
|
+
const transactionsContent = options.transactions.map((trn) => generateTransaction(trn)).join(`
|
|
428
|
+
`);
|
|
429
|
+
let fiContent = "";
|
|
430
|
+
if (options.financialInstitution) {
|
|
431
|
+
fiContent = `<FI>
|
|
432
|
+
`;
|
|
433
|
+
if (options.financialInstitution.org) {
|
|
434
|
+
fiContent += `<ORG>${escapeOfxText(options.financialInstitution.org)}
|
|
435
|
+
`;
|
|
436
|
+
}
|
|
437
|
+
if (options.financialInstitution.fid) {
|
|
438
|
+
fiContent += `<FID>${escapeOfxText(options.financialInstitution.fid)}
|
|
439
|
+
`;
|
|
440
|
+
}
|
|
441
|
+
fiContent += `</FI>
|
|
442
|
+
`;
|
|
443
|
+
}
|
|
444
|
+
let ledgerBalContent = "";
|
|
445
|
+
if (options.ledgerBalance) {
|
|
446
|
+
ledgerBalContent = `<LEDGERBAL>
|
|
447
|
+
<BALAMT>${formatAmount(options.ledgerBalance.amount)}
|
|
448
|
+
<DTASOF>${formatOfxDate(options.ledgerBalance.asOfDate)}
|
|
449
|
+
</LEDGERBAL>
|
|
450
|
+
`;
|
|
451
|
+
}
|
|
452
|
+
let availBalContent = "";
|
|
453
|
+
if (options.availableBalance) {
|
|
454
|
+
availBalContent = `<AVAILBAL>
|
|
455
|
+
<BALAMT>${formatAmount(options.availableBalance.amount)}
|
|
456
|
+
<DTASOF>${formatOfxDate(options.availableBalance.asOfDate)}
|
|
457
|
+
</AVAILBAL>
|
|
458
|
+
`;
|
|
459
|
+
}
|
|
460
|
+
return `${header}<OFX>
|
|
461
|
+
<SIGNONMSGSRSV1>
|
|
462
|
+
<SONRS>
|
|
463
|
+
<STATUS>
|
|
464
|
+
<CODE>0
|
|
465
|
+
<SEVERITY>INFO
|
|
466
|
+
</STATUS>
|
|
467
|
+
<DTSERVER>${serverDate}
|
|
468
|
+
<LANGUAGE>${language}
|
|
469
|
+
${fiContent}</SONRS>
|
|
470
|
+
</SIGNONMSGSRSV1>
|
|
471
|
+
<BANKMSGSRSV1>
|
|
472
|
+
<STMTTRNRS>
|
|
473
|
+
<TRNUID>0
|
|
474
|
+
<STATUS>
|
|
475
|
+
<CODE>0
|
|
476
|
+
<SEVERITY>INFO
|
|
477
|
+
</STATUS>
|
|
478
|
+
<STMTRS>
|
|
479
|
+
<CURDEF>${options.currency}
|
|
480
|
+
<BANKACCTFROM>
|
|
481
|
+
<BANKID>${escapeOfxText(options.bankId)}
|
|
482
|
+
<ACCTID>${escapeOfxText(options.accountId)}
|
|
483
|
+
<ACCTTYPE>${options.accountType}
|
|
484
|
+
</BANKACCTFROM>
|
|
485
|
+
<BANKTRANLIST>
|
|
486
|
+
<DTSTART>${formatOfxDate(options.startDate)}
|
|
487
|
+
<DTEND>${formatOfxDate(options.endDate)}
|
|
488
|
+
${transactionsContent}
|
|
489
|
+
</BANKTRANLIST>
|
|
490
|
+
${ledgerBalContent}${availBalContent}</STMTRS>
|
|
491
|
+
</STMTTRNRS>
|
|
492
|
+
</BANKMSGSRSV1>
|
|
493
|
+
</OFX>`;
|
|
494
|
+
}
|
|
495
|
+
function generateCreditCardStatement(options) {
|
|
496
|
+
const header = generateHeader();
|
|
497
|
+
const serverDate = formatOfxDate(new Date);
|
|
498
|
+
const language = options.language ?? "POR";
|
|
499
|
+
const transactionsContent = options.transactions.map((trn) => generateTransaction(trn)).join(`
|
|
500
|
+
`);
|
|
501
|
+
let fiContent = "";
|
|
502
|
+
if (options.financialInstitution) {
|
|
503
|
+
fiContent = `<FI>
|
|
504
|
+
`;
|
|
505
|
+
if (options.financialInstitution.org) {
|
|
506
|
+
fiContent += `<ORG>${escapeOfxText(options.financialInstitution.org)}
|
|
507
|
+
`;
|
|
508
|
+
}
|
|
509
|
+
if (options.financialInstitution.fid) {
|
|
510
|
+
fiContent += `<FID>${escapeOfxText(options.financialInstitution.fid)}
|
|
511
|
+
`;
|
|
512
|
+
}
|
|
513
|
+
fiContent += `</FI>
|
|
514
|
+
`;
|
|
515
|
+
}
|
|
516
|
+
let ledgerBalContent = "";
|
|
517
|
+
if (options.ledgerBalance) {
|
|
518
|
+
ledgerBalContent = `<LEDGERBAL>
|
|
519
|
+
<BALAMT>${formatAmount(options.ledgerBalance.amount)}
|
|
520
|
+
<DTASOF>${formatOfxDate(options.ledgerBalance.asOfDate)}
|
|
521
|
+
</LEDGERBAL>
|
|
522
|
+
`;
|
|
523
|
+
}
|
|
524
|
+
let availBalContent = "";
|
|
525
|
+
if (options.availableBalance) {
|
|
526
|
+
availBalContent = `<AVAILBAL>
|
|
527
|
+
<BALAMT>${formatAmount(options.availableBalance.amount)}
|
|
528
|
+
<DTASOF>${formatOfxDate(options.availableBalance.asOfDate)}
|
|
529
|
+
</AVAILBAL>
|
|
530
|
+
`;
|
|
531
|
+
}
|
|
532
|
+
return `${header}<OFX>
|
|
533
|
+
<SIGNONMSGSRSV1>
|
|
534
|
+
<SONRS>
|
|
535
|
+
<STATUS>
|
|
536
|
+
<CODE>0
|
|
537
|
+
<SEVERITY>INFO
|
|
538
|
+
</STATUS>
|
|
539
|
+
<DTSERVER>${serverDate}
|
|
540
|
+
<LANGUAGE>${language}
|
|
541
|
+
${fiContent}</SONRS>
|
|
542
|
+
</SIGNONMSGSRSV1>
|
|
543
|
+
<CREDITCARDMSGSRSV1>
|
|
544
|
+
<CCSTMTTRNRS>
|
|
545
|
+
<TRNUID>0
|
|
546
|
+
<STATUS>
|
|
547
|
+
<CODE>0
|
|
548
|
+
<SEVERITY>INFO
|
|
549
|
+
</STATUS>
|
|
550
|
+
<CCSTMTRS>
|
|
551
|
+
<CURDEF>${options.currency}
|
|
552
|
+
<CCACCTFROM>
|
|
553
|
+
<ACCTID>${escapeOfxText(options.accountId)}
|
|
554
|
+
</CCACCTFROM>
|
|
555
|
+
<BANKTRANLIST>
|
|
556
|
+
<DTSTART>${formatOfxDate(options.startDate)}
|
|
557
|
+
<DTEND>${formatOfxDate(options.endDate)}
|
|
558
|
+
${transactionsContent}
|
|
559
|
+
</BANKTRANLIST>
|
|
560
|
+
${ledgerBalContent}${availBalContent}</CCSTMTRS>
|
|
561
|
+
</CCSTMTTRNRS>
|
|
562
|
+
</CREDITCARDMSGSRSV1>
|
|
563
|
+
</OFX>`;
|
|
564
|
+
}
|
|
361
565
|
export {
|
|
362
566
|
schemas,
|
|
363
567
|
parseOrThrow,
|
|
@@ -365,5 +569,9 @@ export {
|
|
|
365
569
|
getTransactions,
|
|
366
570
|
getSignOnInfo,
|
|
367
571
|
getBalance,
|
|
368
|
-
getAccountInfo
|
|
572
|
+
getAccountInfo,
|
|
573
|
+
generateHeader,
|
|
574
|
+
generateCreditCardStatement,
|
|
575
|
+
generateBankStatement,
|
|
576
|
+
formatOfxDate
|
|
369
577
|
};
|
package/package.json
CHANGED
|
@@ -16,10 +16,12 @@
|
|
|
16
16
|
},
|
|
17
17
|
"exports": {
|
|
18
18
|
".": {
|
|
19
|
+
"bun": "./src/index.ts",
|
|
19
20
|
"import": {
|
|
20
21
|
"default": "./dist/index.js",
|
|
21
22
|
"types": "./dist/index.d.ts"
|
|
22
|
-
}
|
|
23
|
+
},
|
|
24
|
+
"types": "./src/index.ts"
|
|
23
25
|
},
|
|
24
26
|
"./package.json": "./package.json"
|
|
25
27
|
},
|
|
@@ -52,6 +54,7 @@
|
|
|
52
54
|
"lint": "biome check .",
|
|
53
55
|
"lint:fix": "biome check --write .",
|
|
54
56
|
"postinstall": "bun simple-git-hooks",
|
|
57
|
+
"publish": "bunx npm publish",
|
|
55
58
|
"release": "bumpp --commit --push --tag",
|
|
56
59
|
"test": "bun test",
|
|
57
60
|
"test:coverage": "bun test --coverage",
|
|
@@ -63,5 +66,5 @@
|
|
|
63
66
|
},
|
|
64
67
|
"type": "module",
|
|
65
68
|
"types": "./dist/index.d.ts",
|
|
66
|
-
"version": "1.2.
|
|
69
|
+
"version": "1.2.1"
|
|
67
70
|
}
|