lib-fints 1.0.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.
Files changed (306) hide show
  1. package/LICENSE +504 -0
  2. package/README.md +216 -0
  3. package/dist/accountBalance.js +1 -0
  4. package/dist/bankAccount.js +34 -0
  5. package/dist/bankAnswer.js +1 -0
  6. package/dist/bankTransaction.js +1 -0
  7. package/dist/bankingInformation.js +1 -0
  8. package/dist/bpd.js +1 -0
  9. package/dist/client.js +165 -0
  10. package/dist/codes.js +79 -0
  11. package/dist/config.js +181 -0
  12. package/dist/dataElements/AlphaNumeric.js +24 -0
  13. package/dist/dataElements/Amount.js +6 -0
  14. package/dist/dataElements/Binary.js +20 -0
  15. package/dist/dataElements/Country.js +6 -0
  16. package/dist/dataElements/Currency.js +6 -0
  17. package/dist/dataElements/Dat.js +18 -0
  18. package/dist/dataElements/DataElement.js +37 -0
  19. package/dist/dataElements/Digits.js +23 -0
  20. package/dist/dataElements/Float.js +21 -0
  21. package/dist/dataElements/Identification.js +6 -0
  22. package/dist/dataElements/Numeric.js +26 -0
  23. package/dist/dataElements/Text.js +21 -0
  24. package/dist/dataElements/Time.js +18 -0
  25. package/dist/dataElements/YesNo.js +18 -0
  26. package/dist/dataGroups/Account.js +12 -0
  27. package/dist/dataGroups/Balance.js +15 -0
  28. package/dist/dataGroups/BankIdentification.js +8 -0
  29. package/dist/dataGroups/DataGroup.js +54 -0
  30. package/dist/dataGroups/InternationalAccount.js +15 -0
  31. package/dist/dataGroups/Money.js +8 -0
  32. package/dist/dataGroups/RefMessage.js +8 -0
  33. package/dist/dataGroups/TimeStamp.js +8 -0
  34. package/dist/decoder.js +97 -0
  35. package/dist/dialog.js +189 -0
  36. package/dist/encoder.js +47 -0
  37. package/dist/format.js +6 -0
  38. package/dist/httpClient.js +41 -0
  39. package/dist/httpClientNode.js +59 -0
  40. package/dist/index.js +15 -0
  41. package/dist/interactions/balanceInteraction.js +47 -0
  42. package/dist/interactions/customerInteraction.js +55 -0
  43. package/dist/interactions/initDialogInteraction.js +155 -0
  44. package/dist/interactions/statementInteraction.js +44 -0
  45. package/dist/interactions/tanMediaInteraction.js +27 -0
  46. package/dist/message.js +198 -0
  47. package/dist/mt940parser.js +307 -0
  48. package/dist/parser.js +30 -0
  49. package/dist/partedSegment.js +8 -0
  50. package/dist/segment.js +59 -0
  51. package/dist/segmentDefinition.js +11 -0
  52. package/dist/segmentHeader.js +13 -0
  53. package/dist/segments/HIBPA.js +23 -0
  54. package/dist/segments/HIKAZ.js +13 -0
  55. package/dist/segments/HIKAZS.js +13 -0
  56. package/dist/segments/HIKIM.js +11 -0
  57. package/dist/segments/HIKOM.js +23 -0
  58. package/dist/segments/HIPINS.js +22 -0
  59. package/dist/segments/HIRMG.js +20 -0
  60. package/dist/segments/HIRMS.js +20 -0
  61. package/dist/segments/HISAL.js +31 -0
  62. package/dist/segments/HISYN.js +16 -0
  63. package/dist/segments/HITAB.js +37 -0
  64. package/dist/segments/HITAN.js +23 -0
  65. package/dist/segments/HITANS.js +48 -0
  66. package/dist/segments/HIUPA.js +18 -0
  67. package/dist/segments/HIUPD.js +34 -0
  68. package/dist/segments/HKEND.js +11 -0
  69. package/dist/segments/HKIDN.js +18 -0
  70. package/dist/segments/HKKAZ.js +24 -0
  71. package/dist/segments/HKSAL.js +21 -0
  72. package/dist/segments/HKSYN.js +11 -0
  73. package/dist/segments/HKTAB.js +12 -0
  74. package/dist/segments/HKTAN.js +35 -0
  75. package/dist/segments/HKVVB.js +18 -0
  76. package/dist/segments/HNHBK.js +20 -0
  77. package/dist/segments/HNHBS.js +11 -0
  78. package/dist/segments/HNSHA.js +17 -0
  79. package/dist/segments/HNSHK.js +43 -0
  80. package/dist/segments/HNVSD.js +11 -0
  81. package/dist/segments/HNVSK.js +45 -0
  82. package/dist/segments/businessTransactionParameter.js +20 -0
  83. package/dist/segments/registry.js +71 -0
  84. package/dist/tanMethod.js +1 -0
  85. package/dist/tests/HIBPA.test.js +26 -0
  86. package/dist/tests/HIPINS.test.js +14 -0
  87. package/dist/tests/HIRMG.test.js +24 -0
  88. package/dist/tests/HITAB.test.js +19 -0
  89. package/dist/tests/HITANS.test.js +19 -0
  90. package/dist/tests/HIUPA.test.js +11 -0
  91. package/dist/tests/HIUPD.test.js +11 -0
  92. package/dist/tests/HKIDN.test.js +22 -0
  93. package/dist/tests/HKSAL.test.js +45 -0
  94. package/dist/tests/HKTAN.test.js +21 -0
  95. package/dist/tests/HNSHK.test.js +11 -0
  96. package/dist/tests/HNVSK.test.js +11 -0
  97. package/dist/tests/client.test.js +33 -0
  98. package/dist/tests/datatypes.test.js +8 -0
  99. package/dist/tests/message.test.js +80 -0
  100. package/dist/tests/mt940parser.test.js +56 -0
  101. package/dist/tests/parser.test.js +20 -0
  102. package/dist/types/accountBalance.d.ts +9 -0
  103. package/dist/types/accountBalance.d.ts.map +1 -0
  104. package/dist/types/bankAccount.d.ts +27 -0
  105. package/dist/types/bankAccount.d.ts.map +1 -0
  106. package/dist/types/bankAnswer.d.ts +6 -0
  107. package/dist/types/bankAnswer.d.ts.map +1 -0
  108. package/dist/types/bankTransaction.d.ts +6 -0
  109. package/dist/types/bankTransaction.d.ts.map +1 -0
  110. package/dist/types/bankingInformation.d.ts +20 -0
  111. package/dist/types/bankingInformation.d.ts.map +1 -0
  112. package/dist/types/bpd.d.ts +17 -0
  113. package/dist/types/bpd.d.ts.map +1 -0
  114. package/dist/types/client.d.ts +86 -0
  115. package/dist/types/client.d.ts.map +1 -0
  116. package/dist/types/codes.d.ts +68 -0
  117. package/dist/types/codes.d.ts.map +1 -0
  118. package/dist/types/config.d.ts +99 -0
  119. package/dist/types/config.d.ts.map +1 -0
  120. package/dist/types/dataElements/AlphaNumeric.d.ts +8 -0
  121. package/dist/types/dataElements/AlphaNumeric.d.ts.map +1 -0
  122. package/dist/types/dataElements/Amount.d.ts +5 -0
  123. package/dist/types/dataElements/Amount.d.ts.map +1 -0
  124. package/dist/types/dataElements/Binary.d.ts +8 -0
  125. package/dist/types/dataElements/Binary.d.ts.map +1 -0
  126. package/dist/types/dataElements/Country.d.ts +5 -0
  127. package/dist/types/dataElements/Country.d.ts.map +1 -0
  128. package/dist/types/dataElements/Currency.d.ts +5 -0
  129. package/dist/types/dataElements/Currency.d.ts.map +1 -0
  130. package/dist/types/dataElements/Dat.d.ts +8 -0
  131. package/dist/types/dataElements/Dat.d.ts.map +1 -0
  132. package/dist/types/dataElements/DataElement.d.ts +14 -0
  133. package/dist/types/dataElements/DataElement.d.ts.map +1 -0
  134. package/dist/types/dataElements/Digits.d.ts +8 -0
  135. package/dist/types/dataElements/Digits.d.ts.map +1 -0
  136. package/dist/types/dataElements/Float.d.ts +8 -0
  137. package/dist/types/dataElements/Float.d.ts.map +1 -0
  138. package/dist/types/dataElements/Identification.d.ts +5 -0
  139. package/dist/types/dataElements/Identification.d.ts.map +1 -0
  140. package/dist/types/dataElements/Numeric.d.ts +9 -0
  141. package/dist/types/dataElements/Numeric.d.ts.map +1 -0
  142. package/dist/types/dataElements/Text.d.ts +8 -0
  143. package/dist/types/dataElements/Text.d.ts.map +1 -0
  144. package/dist/types/dataElements/Time.d.ts +8 -0
  145. package/dist/types/dataElements/Time.d.ts.map +1 -0
  146. package/dist/types/dataElements/YesNo.d.ts +7 -0
  147. package/dist/types/dataElements/YesNo.d.ts.map +1 -0
  148. package/dist/types/dataGroups/Account.d.ts +14 -0
  149. package/dist/types/dataGroups/Account.d.ts.map +1 -0
  150. package/dist/types/dataGroups/Balance.d.ts +12 -0
  151. package/dist/types/dataGroups/Balance.d.ts.map +1 -0
  152. package/dist/types/dataGroups/BankIdentification.d.ts +5 -0
  153. package/dist/types/dataGroups/BankIdentification.d.ts.map +1 -0
  154. package/dist/types/dataGroups/DataGroup.d.ts +10 -0
  155. package/dist/types/dataGroups/DataGroup.d.ts.map +1 -0
  156. package/dist/types/dataGroups/InternationalAccount.d.ts +13 -0
  157. package/dist/types/dataGroups/InternationalAccount.d.ts.map +1 -0
  158. package/dist/types/dataGroups/Money.d.ts +9 -0
  159. package/dist/types/dataGroups/Money.d.ts.map +1 -0
  160. package/dist/types/dataGroups/RefMessage.d.ts +9 -0
  161. package/dist/types/dataGroups/RefMessage.d.ts.map +1 -0
  162. package/dist/types/dataGroups/TimeStamp.d.ts +9 -0
  163. package/dist/types/dataGroups/TimeStamp.d.ts.map +1 -0
  164. package/dist/types/decoder.d.ts +4 -0
  165. package/dist/types/decoder.d.ts.map +1 -0
  166. package/dist/types/dialog.d.ts +21 -0
  167. package/dist/types/dialog.d.ts.map +1 -0
  168. package/dist/types/encoder.d.ts +3 -0
  169. package/dist/types/encoder.d.ts.map +1 -0
  170. package/dist/types/format.d.ts +3 -0
  171. package/dist/types/format.d.ts.map +1 -0
  172. package/dist/types/httpClient.d.ts +8 -0
  173. package/dist/types/httpClient.d.ts.map +1 -0
  174. package/dist/types/httpClientNode.d.ts +8 -0
  175. package/dist/types/httpClientNode.d.ts.map +1 -0
  176. package/dist/types/index.d.ts +17 -0
  177. package/dist/types/index.d.ts.map +1 -0
  178. package/dist/types/interactions/balanceInteraction.d.ts +15 -0
  179. package/dist/types/interactions/balanceInteraction.d.ts.map +1 -0
  180. package/dist/types/interactions/customerInteraction.d.ts +41 -0
  181. package/dist/types/interactions/customerInteraction.d.ts.map +1 -0
  182. package/dist/types/interactions/initDialogInteraction.d.ts +16 -0
  183. package/dist/types/interactions/initDialogInteraction.d.ts.map +1 -0
  184. package/dist/types/interactions/statementInteraction.d.ts +17 -0
  185. package/dist/types/interactions/statementInteraction.d.ts.map +1 -0
  186. package/dist/types/interactions/tanMediaInteraction.d.ts +13 -0
  187. package/dist/types/interactions/tanMediaInteraction.d.ts.map +1 -0
  188. package/dist/types/message.d.ts +30 -0
  189. package/dist/types/message.d.ts.map +1 -0
  190. package/dist/types/mt940parser.d.ts +83 -0
  191. package/dist/types/mt940parser.d.ts.map +1 -0
  192. package/dist/types/parser.d.ts +2 -0
  193. package/dist/types/parser.d.ts.map +1 -0
  194. package/dist/types/partedSegment.d.ts +14 -0
  195. package/dist/types/partedSegment.d.ts.map +1 -0
  196. package/dist/types/segment.d.ts +11 -0
  197. package/dist/types/segment.d.ts.map +1 -0
  198. package/dist/types/segmentDefinition.d.ts +11 -0
  199. package/dist/types/segmentDefinition.d.ts.map +1 -0
  200. package/dist/types/segmentHeader.d.ts +11 -0
  201. package/dist/types/segmentHeader.d.ts.map +1 -0
  202. package/dist/types/segments/HIBPA.d.ts +27 -0
  203. package/dist/types/segments/HIBPA.d.ts.map +1 -0
  204. package/dist/types/segments/HIKAZ.d.ts +16 -0
  205. package/dist/types/segments/HIKAZ.d.ts.map +1 -0
  206. package/dist/types/segments/HIKAZS.d.ts +16 -0
  207. package/dist/types/segments/HIKAZS.d.ts.map +1 -0
  208. package/dist/types/segments/HIKIM.d.ts +17 -0
  209. package/dist/types/segments/HIKIM.d.ts.map +1 -0
  210. package/dist/types/segments/HIKOM.d.ts +27 -0
  211. package/dist/types/segments/HIKOM.d.ts.map +1 -0
  212. package/dist/types/segments/HIPINS.d.ts +23 -0
  213. package/dist/types/segments/HIPINS.d.ts.map +1 -0
  214. package/dist/types/segments/HIRMG.d.ts +22 -0
  215. package/dist/types/segments/HIRMG.d.ts.map +1 -0
  216. package/dist/types/segments/HIRMS.d.ts +17 -0
  217. package/dist/types/segments/HIRMS.d.ts.map +1 -0
  218. package/dist/types/segments/HISAL.d.ts +32 -0
  219. package/dist/types/segments/HISAL.d.ts.map +1 -0
  220. package/dist/types/segments/HISYN.d.ts +19 -0
  221. package/dist/types/segments/HISYN.d.ts.map +1 -0
  222. package/dist/types/segments/HITAB.d.ts +39 -0
  223. package/dist/types/segments/HITAB.d.ts.map +1 -0
  224. package/dist/types/segments/HITAN.d.ts +25 -0
  225. package/dist/types/segments/HITAN.d.ts.map +1 -0
  226. package/dist/types/segments/HITANS.d.ts +41 -0
  227. package/dist/types/segments/HITANS.d.ts.map +1 -0
  228. package/dist/types/segments/HIUPA.d.ts +21 -0
  229. package/dist/types/segments/HIUPA.d.ts.map +1 -0
  230. package/dist/types/segments/HIUPD.d.ts +42 -0
  231. package/dist/types/segments/HIUPD.d.ts.map +1 -0
  232. package/dist/types/segments/HKEND.d.ts +16 -0
  233. package/dist/types/segments/HKEND.d.ts.map +1 -0
  234. package/dist/types/segments/HKIDN.d.ts +22 -0
  235. package/dist/types/segments/HKIDN.d.ts.map +1 -0
  236. package/dist/types/segments/HKKAZ.d.ts +25 -0
  237. package/dist/types/segments/HKKAZ.d.ts.map +1 -0
  238. package/dist/types/segments/HKSAL.d.ts +22 -0
  239. package/dist/types/segments/HKSAL.d.ts.map +1 -0
  240. package/dist/types/segments/HKSYN.d.ts +17 -0
  241. package/dist/types/segments/HKSYN.d.ts.map +1 -0
  242. package/dist/types/segments/HKTAB.d.ts +19 -0
  243. package/dist/types/segments/HKTAB.d.ts.map +1 -0
  244. package/dist/types/segments/HKTAN.d.ts +39 -0
  245. package/dist/types/segments/HKTAN.d.ts.map +1 -0
  246. package/dist/types/segments/HKVVB.d.ts +22 -0
  247. package/dist/types/segments/HKVVB.d.ts.map +1 -0
  248. package/dist/types/segments/HNHBK.d.ts +23 -0
  249. package/dist/types/segments/HNHBK.d.ts.map +1 -0
  250. package/dist/types/segments/HNHBS.d.ts +16 -0
  251. package/dist/types/segments/HNHBS.d.ts.map +1 -0
  252. package/dist/types/segments/HNSHA.d.ts +24 -0
  253. package/dist/types/segments/HNSHA.d.ts.map +1 -0
  254. package/dist/types/segments/HNSHK.d.ts +66 -0
  255. package/dist/types/segments/HNSHK.d.ts.map +1 -0
  256. package/dist/types/segments/HNVSD.d.ts +20 -0
  257. package/dist/types/segments/HNVSD.d.ts.map +1 -0
  258. package/dist/types/segments/HNVSK.d.ts +40 -0
  259. package/dist/types/segments/HNVSK.d.ts.map +1 -0
  260. package/dist/types/segments/businessTransactionParameter.d.ts +18 -0
  261. package/dist/types/segments/businessTransactionParameter.d.ts.map +1 -0
  262. package/dist/types/segments/registry.d.ts +4 -0
  263. package/dist/types/segments/registry.d.ts.map +1 -0
  264. package/dist/types/tanMethod.d.ts +10 -0
  265. package/dist/types/tanMethod.d.ts.map +1 -0
  266. package/dist/types/tests/HIBPA.test.d.ts +2 -0
  267. package/dist/types/tests/HIBPA.test.d.ts.map +1 -0
  268. package/dist/types/tests/HIPINS.test.d.ts +2 -0
  269. package/dist/types/tests/HIPINS.test.d.ts.map +1 -0
  270. package/dist/types/tests/HIRMG.test.d.ts +2 -0
  271. package/dist/types/tests/HIRMG.test.d.ts.map +1 -0
  272. package/dist/types/tests/HITAB.test.d.ts +2 -0
  273. package/dist/types/tests/HITAB.test.d.ts.map +1 -0
  274. package/dist/types/tests/HITANS.test.d.ts +2 -0
  275. package/dist/types/tests/HITANS.test.d.ts.map +1 -0
  276. package/dist/types/tests/HIUPA.test.d.ts +2 -0
  277. package/dist/types/tests/HIUPA.test.d.ts.map +1 -0
  278. package/dist/types/tests/HIUPD.test.d.ts +2 -0
  279. package/dist/types/tests/HIUPD.test.d.ts.map +1 -0
  280. package/dist/types/tests/HKIDN.test.d.ts +2 -0
  281. package/dist/types/tests/HKIDN.test.d.ts.map +1 -0
  282. package/dist/types/tests/HKSAL.test.d.ts +2 -0
  283. package/dist/types/tests/HKSAL.test.d.ts.map +1 -0
  284. package/dist/types/tests/HKTAN.test.d.ts +2 -0
  285. package/dist/types/tests/HKTAN.test.d.ts.map +1 -0
  286. package/dist/types/tests/HNSHK.test.d.ts +2 -0
  287. package/dist/types/tests/HNSHK.test.d.ts.map +1 -0
  288. package/dist/types/tests/HNVSK.test.d.ts +2 -0
  289. package/dist/types/tests/HNVSK.test.d.ts.map +1 -0
  290. package/dist/types/tests/client.test.d.ts +2 -0
  291. package/dist/types/tests/client.test.d.ts.map +1 -0
  292. package/dist/types/tests/datatypes.test.d.ts +2 -0
  293. package/dist/types/tests/datatypes.test.d.ts.map +1 -0
  294. package/dist/types/tests/message.test.d.ts +2 -0
  295. package/dist/types/tests/message.test.d.ts.map +1 -0
  296. package/dist/types/tests/mt940parser.test.d.ts +2 -0
  297. package/dist/types/tests/mt940parser.test.d.ts.map +1 -0
  298. package/dist/types/tests/parser.test.d.ts +2 -0
  299. package/dist/types/tests/parser.test.d.ts.map +1 -0
  300. package/dist/types/unknownSegment.d.ts +14 -0
  301. package/dist/types/unknownSegment.d.ts.map +1 -0
  302. package/dist/types/upd.d.ts +8 -0
  303. package/dist/types/upd.d.ts.map +1 -0
  304. package/dist/unknownSegment.js +8 -0
  305. package/dist/upd.js +1 -0
  306. package/package.json +45 -0
@@ -0,0 +1,307 @@
1
+ export var TokenType;
2
+ (function (TokenType) {
3
+ TokenType["Tag"] = "Tag";
4
+ TokenType["SubTag"] = "SubTag";
5
+ TokenType["PurposeTag"] = "PurposeTag";
6
+ TokenType["SingleAlpha"] = "SingleAlpha";
7
+ TokenType["StatementNumber"] = "StatementNumber";
8
+ TokenType["CustomerReference"] = "CustomerReference";
9
+ TokenType["BankReference"] = "BankReference";
10
+ TokenType["Date"] = "Date";
11
+ TokenType["ShortDate"] = "ShortDate";
12
+ TokenType["CreditDebit"] = "CreditDebit";
13
+ TokenType["Decimal"] = "Decimal";
14
+ TokenType["Currency"] = "Currency";
15
+ TokenType["TextToEndOfLine"] = "TextToEndOfLine";
16
+ TokenType["TextToNextSubTag"] = "TextToNextSubTag";
17
+ TokenType["TextToNextPurposeTag"] = "TextToNextPurposeTag";
18
+ TokenType["NextNonTagLine"] = "NextNonTagLine";
19
+ TokenType["TransactionType"] = "TransactionType";
20
+ TokenType["TransactionCode"] = "TransactionCode";
21
+ TokenType["WhiteSpace"] = "WhiteSpace";
22
+ })(TokenType || (TokenType = {}));
23
+ const tokens = {
24
+ Tag: /^:\d\d[A-Z]?:/,
25
+ SubTag: /^\?\d\d/,
26
+ PurposeTag: /^[A-Z]{4}\+/,
27
+ SingleAlpha: /^[A-Z]/,
28
+ StatementNumber: /^\d+\/?\d*/,
29
+ CustomerReference: /^[^\/\r\n]+/,
30
+ BankReference: /^\/\/([^\r\n]+)/,
31
+ CreditDebit: /^C|D|RC|RD/,
32
+ Date: /^\d{6}/,
33
+ ShortDate: /^\d{4}/,
34
+ Decimal: /^\d+,\d*/,
35
+ Currency: /^[A-Z]{3}/,
36
+ TextToEndOfLine: /^[^\r\n]+/,
37
+ TextToNextSubTag: /^[^\?]+/,
38
+ TextToNextPurposeTag: /^(.*?)(?=\s[A-Z]{4}\+|$)/,
39
+ NextNonTagLine: /^\r\n([^:][^\r\n]*)/,
40
+ TransactionType: /^[A-Z][0-9A-Z]{3}/,
41
+ TransactionCode: /^\d{3}/,
42
+ WhiteSpace: /^\s+/,
43
+ };
44
+ export class Mt940Parser {
45
+ input;
46
+ tokenizer;
47
+ statements = [];
48
+ currentStatement = {
49
+ transactions: [],
50
+ };
51
+ currentTransaction;
52
+ constructor(input) {
53
+ this.input = input;
54
+ this.tokenizer = new Mt940Tokenizer(input);
55
+ }
56
+ parse() {
57
+ while (!this.tokenizer.isAtEnd()) {
58
+ if (this.tokenizer.parseNextToken(TokenType.WhiteSpace, false)) {
59
+ continue;
60
+ }
61
+ let tag = this.tokenizer.parseNextToken(TokenType.Tag, false);
62
+ if (tag) {
63
+ switch (tag) {
64
+ case ':20:':
65
+ this.currentStatement = {
66
+ transactions: [],
67
+ };
68
+ this.statements.push(this.currentStatement);
69
+ this.currentStatement.transactionReference = this.tokenizer.parseNextToken(TokenType.TextToEndOfLine, true);
70
+ break;
71
+ case ':21:':
72
+ this.currentStatement.relatedReference = this.tokenizer.parseNextToken(TokenType.TextToEndOfLine, false);
73
+ break;
74
+ case ':25:':
75
+ this.currentStatement.account = this.tokenizer.parseNextToken(TokenType.TextToEndOfLine, true);
76
+ break;
77
+ case ':28C:':
78
+ this.currentStatement.number = this.tokenizer.parseNextToken(TokenType.StatementNumber, true);
79
+ break;
80
+ case ':60F:':
81
+ this.currentStatement.openingBalance = this.parseBalance();
82
+ break;
83
+ case ':62F:':
84
+ this.currentStatement.closingBalance = this.parseBalance();
85
+ break;
86
+ case ':64:':
87
+ this.currentStatement.availableBalance = this.parseBalance();
88
+ break;
89
+ case ':65:':
90
+ if (!this.currentStatement.forwardBalances) {
91
+ this.currentStatement.forwardBalances = [];
92
+ }
93
+ this.currentStatement.forwardBalances.push(this.parseBalance());
94
+ break;
95
+ case ':61:':
96
+ const valueDate = this.parseDate(true);
97
+ let entryDate = valueDate;
98
+ let entryDateString = this.tokenizer.parseNextToken(TokenType.ShortDate, false);
99
+ if (entryDateString) {
100
+ const valueYear = valueDate.getFullYear();
101
+ const valueMonth = valueDate.getMonth() + 1;
102
+ const entryMonth = parseInt(entryDateString.substring(0, 2));
103
+ const entryDay = parseInt(entryDateString.substring(2, 4));
104
+ const entryYear = entryMonth <= valueMonth ? valueYear : valueYear - 1;
105
+ entryDate = new Date(entryYear, entryMonth - 1, entryDay);
106
+ }
107
+ else {
108
+ entryDate = valueDate;
109
+ }
110
+ const creditDebit = this.tokenizer.parseNextToken(TokenType.CreditDebit, true);
111
+ const fundsCode = this.tokenizer.parseNextToken(TokenType.SingleAlpha, false);
112
+ const amount = this.parseAmount(creditDebit, true);
113
+ const transactionType = this.tokenizer.parseNextToken(TokenType.TransactionType, true);
114
+ const customerReference = this.tokenizer.parseNextToken(TokenType.CustomerReference, true);
115
+ const bankReference = this.tokenizer.parseNextToken(TokenType.BankReference, false);
116
+ const additionalInformation = this.tokenizer.parseNextToken(TokenType.NextNonTagLine, false);
117
+ this.currentTransaction = {
118
+ valueDate: valueDate,
119
+ entryDate: entryDate,
120
+ fundsCode: fundsCode,
121
+ amount: amount,
122
+ transactionType: transactionType,
123
+ customerReference: customerReference,
124
+ bankReference: bankReference,
125
+ additionalInformation: additionalInformation,
126
+ };
127
+ this.currentStatement.transactions.push(this.currentTransaction);
128
+ break;
129
+ case ':86:':
130
+ let infoToAccountOwner = this.tokenizer.parseNextToken(TokenType.TextToEndOfLine, true);
131
+ let nextLine;
132
+ do {
133
+ nextLine = this.tokenizer.parseNextToken(TokenType.NextNonTagLine, false);
134
+ if (nextLine) {
135
+ infoToAccountOwner += nextLine;
136
+ }
137
+ } while (nextLine);
138
+ this.parseInfoToAccountOwner(infoToAccountOwner);
139
+ break;
140
+ default:
141
+ this.tokenizer.parseNextToken(TokenType.TextToEndOfLine, false);
142
+ break;
143
+ }
144
+ }
145
+ else {
146
+ this.tokenizer.parseNextToken(TokenType.TextToEndOfLine, false);
147
+ }
148
+ }
149
+ return this.statements;
150
+ }
151
+ parseInfoToAccountOwner(infoToAccountOwner) {
152
+ if (!this.currentTransaction) {
153
+ return;
154
+ }
155
+ const subFieldTokenizer = new Mt940Tokenizer(infoToAccountOwner);
156
+ this.currentTransaction.transactionCode = subFieldTokenizer.parseNextToken(TokenType.TransactionCode, false);
157
+ let subTag;
158
+ do {
159
+ subTag = subFieldTokenizer.parseNextToken(TokenType.SubTag, false);
160
+ if (subTag) {
161
+ switch (subTag) {
162
+ case '?00':
163
+ this.currentTransaction.bookingText = subFieldTokenizer.parseNextToken(TokenType.TextToNextSubTag, true);
164
+ break;
165
+ case '?10':
166
+ this.currentTransaction.primeNotesNr = subFieldTokenizer.parseNextToken(TokenType.TextToNextSubTag, true);
167
+ break;
168
+ case '?20':
169
+ case '?21':
170
+ case '?22':
171
+ case '?23':
172
+ case '?24':
173
+ case '?25':
174
+ case '?26':
175
+ case '?27':
176
+ case '?28':
177
+ case '?29':
178
+ case '?60':
179
+ case '?61':
180
+ case '?62':
181
+ case '?63':
182
+ if (!this.currentTransaction.purpose) {
183
+ this.currentTransaction.purpose = '';
184
+ }
185
+ const purposeTag = subFieldTokenizer.parseNextToken(TokenType.PurposeTag, false);
186
+ if (purposeTag) {
187
+ if (this.currentTransaction.purpose) {
188
+ this.currentTransaction.purpose += ' ';
189
+ }
190
+ this.currentTransaction.purpose += purposeTag;
191
+ }
192
+ this.currentTransaction.purpose += subFieldTokenizer.parseNextToken(TokenType.TextToNextSubTag, true);
193
+ break;
194
+ case '?30':
195
+ this.currentTransaction.remoteBankId = subFieldTokenizer.parseNextToken(TokenType.TextToNextSubTag, true);
196
+ break;
197
+ case '?31':
198
+ this.currentTransaction.remoteAccountNumber = subFieldTokenizer.parseNextToken(TokenType.TextToNextSubTag, true);
199
+ break;
200
+ case '?32':
201
+ case '?33':
202
+ if (!this.currentTransaction.remoteName) {
203
+ this.currentTransaction.remoteName = '';
204
+ }
205
+ this.currentTransaction.remoteName += subFieldTokenizer.parseNextToken(TokenType.TextToNextSubTag, true);
206
+ break;
207
+ case '?34':
208
+ this.currentTransaction.textKeyExtension = subFieldTokenizer.parseNextToken(TokenType.TextToNextSubTag, true);
209
+ break;
210
+ default:
211
+ subFieldTokenizer.parseNextToken(TokenType.TextToNextSubTag, false);
212
+ break;
213
+ }
214
+ }
215
+ } while (subTag);
216
+ this.parsePurpose(this.currentTransaction);
217
+ }
218
+ parsePurpose(transaction) {
219
+ const purposeTokenizer = new Mt940Tokenizer(transaction.purpose ?? '');
220
+ do {
221
+ const purposeTag = purposeTokenizer.parseNextToken(TokenType.PurposeTag, false);
222
+ if (purposeTag) {
223
+ let text = purposeTokenizer.parseNextToken(TokenType.TextToNextPurposeTag, false);
224
+ if (!text) {
225
+ text = purposeTokenizer.parseNextToken(TokenType.TextToEndOfLine, false);
226
+ }
227
+ switch (purposeTag) {
228
+ case 'EREF+':
229
+ transaction.e2eReference = text;
230
+ break;
231
+ case 'KREF+':
232
+ transaction.customerReference = text;
233
+ break;
234
+ case 'MREF+':
235
+ transaction.mandateReference = text;
236
+ break;
237
+ case 'CRED+':
238
+ transaction.remoteIdentifier = text;
239
+ break;
240
+ case 'DEBT+':
241
+ transaction.remoteIdentifier = text;
242
+ break;
243
+ case 'ABWA+':
244
+ transaction.client = text;
245
+ break;
246
+ case 'SVWZ+':
247
+ transaction.purpose = text;
248
+ break;
249
+ default:
250
+ break;
251
+ }
252
+ }
253
+ else {
254
+ break;
255
+ }
256
+ purposeTokenizer.parseNextToken(TokenType.WhiteSpace, false);
257
+ } while (!purposeTokenizer.isAtEnd());
258
+ }
259
+ parseBalance() {
260
+ const creditDebit = this.tokenizer.parseNextToken(TokenType.CreditDebit, true);
261
+ const date = this.parseDate(true);
262
+ const currency = this.tokenizer.parseNextToken(TokenType.Currency, true);
263
+ const amount = this.tokenizer.parseNextToken(TokenType.Decimal, true);
264
+ return {
265
+ date: date,
266
+ currency: currency,
267
+ value: parseFloat(amount.replace(',', '.')) * (creditDebit === 'D' ? -1 : 1),
268
+ };
269
+ }
270
+ parseDate(isMandatory = true) {
271
+ const date = this.tokenizer.parseNextToken(TokenType.Date, isMandatory);
272
+ const year = parseInt(date.substring(0, 2)) + 2000;
273
+ const month = parseInt(date.substring(2, 4));
274
+ const day = parseInt(date.substring(4, 6));
275
+ return new Date(year, month - 1, day);
276
+ }
277
+ parseAmount(creditDebit, isMandatory = true) {
278
+ const amount = this.tokenizer.parseNextToken(TokenType.Decimal, isMandatory);
279
+ return parseFloat(amount.replace(',', '.')) * (creditDebit === 'D' || creditDebit == 'RC' ? -1 : 1);
280
+ }
281
+ }
282
+ export class Mt940Tokenizer {
283
+ input;
284
+ position = 0;
285
+ lastToken = '';
286
+ constructor(input) {
287
+ this.input = input;
288
+ }
289
+ parseNextToken(type, isMandatory) {
290
+ let matched = this.match(tokens[type]);
291
+ if (matched) {
292
+ this.position += matched[0].length;
293
+ this.lastToken = matched.length > 1 ? matched[1] : matched[0];
294
+ return this.lastToken;
295
+ }
296
+ if (isMandatory) {
297
+ throw new SyntaxError(`Expected ${type} token at position ${this.position}, after '${this.lastToken}'...`);
298
+ }
299
+ return '';
300
+ }
301
+ match(regExp) {
302
+ return regExp.exec(this.input.substring(this.position));
303
+ }
304
+ isAtEnd() {
305
+ return this.position >= this.input.length;
306
+ }
307
+ }
package/dist/parser.js ADDED
@@ -0,0 +1,30 @@
1
+ export function splitBySeparator(text, separator) {
2
+ const result = [];
3
+ let pos = 0;
4
+ for (let index = 0; index < text.length; index++) {
5
+ const char = text[index];
6
+ if (char === '@' && !isEscaped(text, index)) {
7
+ const next = text.indexOf('@', index + 1);
8
+ const size = Number.parseInt(text.slice(index + 1, next));
9
+ if (size) {
10
+ index = next + size;
11
+ }
12
+ }
13
+ else if (char === separator && !isEscaped(text, index)) {
14
+ result.push(text.slice(pos, index));
15
+ pos = index + 1;
16
+ }
17
+ }
18
+ if (pos < text.length) {
19
+ result.push(text.slice(pos));
20
+ }
21
+ return result;
22
+ }
23
+ function isEscaped(text, pos) {
24
+ let count = 0;
25
+ while (pos > 0 && text[pos - 1] === '?') {
26
+ count++;
27
+ pos--;
28
+ }
29
+ return count % 2 === 1;
30
+ }
@@ -0,0 +1,8 @@
1
+ import { Text } from './dataElements/Text.js';
2
+ import { SegmentDefinition } from './segmentDefinition.js';
3
+ export class PARTED extends SegmentDefinition {
4
+ static Id = this.name;
5
+ version = 1;
6
+ elements = [new Text('rawData', 0, 1)];
7
+ }
8
+ export const PartedId = PARTED.Id;
@@ -0,0 +1,59 @@
1
+ import { decodeElements } from './decoder.js';
2
+ import { UnkownId } from './unknownSegment.js';
3
+ import { getSegmentDefinition } from './segments/registry.js';
4
+ import { SegmentDefinition } from './segmentDefinition.js';
5
+ export function decode(text) {
6
+ const endMarkerIndex = text.lastIndexOf("'");
7
+ if (endMarkerIndex === text.length - 1) {
8
+ text = text.substring(0, text.length - 1);
9
+ }
10
+ const headerText = text.slice(0, text.indexOf('+'));
11
+ const contentText = text.slice(text.indexOf('+') + 1);
12
+ const header = SegmentDefinition.header.decode(headerText, 1);
13
+ const definition = getSegmentDefinition(header.segId);
14
+ if (!definition || definition.version < header.version) {
15
+ return {
16
+ header: { ...header, segId: UnkownId },
17
+ originalId: header.segId,
18
+ rawData: contentText,
19
+ };
20
+ }
21
+ let data = decodeElements(contentText, definition.elements, '+', header.version, header.segId);
22
+ if (Array.isArray(data)) {
23
+ const object = {};
24
+ object[definition.elements[0].name] = data;
25
+ data = object;
26
+ }
27
+ data.header = header;
28
+ return data;
29
+ }
30
+ export function encode(data) {
31
+ const definition = getSegmentDefinition(data.header.segId);
32
+ if (!definition) {
33
+ throw new Error(`Encoding failed, no segment definition registered for '${data.header.segId}'`);
34
+ }
35
+ return definition.encode(data);
36
+ }
37
+ export function segmentToString(segment) {
38
+ const keyedSegment = segment;
39
+ const number = segment.header.segNr?.toString() ?? '?';
40
+ const segId = segment.header.segId === UnkownId ? segment.originalId : segment.header.segId;
41
+ let text = `${number.padStart(4, ' ')}. ${segId} v${segment.header.version}`;
42
+ if (segment.header.refSegNr) {
43
+ text += ` RefSeg: ${segment.header.refSegNr}`;
44
+ }
45
+ const segmentDefinition = getSegmentDefinition(segment.header.segId);
46
+ let texts = segmentDefinition.elements.map((element, index) => {
47
+ if (element.maxCount > 1) {
48
+ return keyedSegment[element.name]
49
+ .map((value) => element.toString(value))
50
+ .filter((text) => !!text)
51
+ .join('; ');
52
+ }
53
+ else {
54
+ return element.toString(keyedSegment[element.name]);
55
+ }
56
+ });
57
+ text += '; ' + texts.filter((text) => !!text).join('; ');
58
+ return text;
59
+ }
@@ -0,0 +1,11 @@
1
+ import { encodeElements } from './encoder.js';
2
+ import { SegmentHeaderGroup } from './segmentHeader.js';
3
+ export class SegmentDefinition {
4
+ id = this.constructor.name;
5
+ static header = new SegmentHeaderGroup();
6
+ encode(data) {
7
+ const headerText = SegmentDefinition.header.encode(data.header, [data.header.segId], data.header.version);
8
+ const elementsText = encodeElements(data, this.elements, '+', data.header.version, [data.header.segId]);
9
+ return `${headerText}+${elementsText}'`;
10
+ }
11
+ }
@@ -0,0 +1,13 @@
1
+ import { Numeric } from './dataElements/Numeric.js';
2
+ import { AlphaNumeric } from './dataElements/AlphaNumeric.js';
3
+ import { DataGroup } from './dataGroups/DataGroup.js';
4
+ export class SegmentHeaderGroup extends DataGroup {
5
+ constructor() {
6
+ super('segHeader', [
7
+ new AlphaNumeric('segId', 1, 1, 6),
8
+ new Numeric('segNr', 1, 1, 3),
9
+ new Numeric('version', 1, 1, 3),
10
+ new Numeric('refSegNr', 0, 1, 3),
11
+ ], 1, 1);
12
+ }
13
+ }
@@ -0,0 +1,23 @@
1
+ import { Numeric } from '../dataElements/Numeric.js';
2
+ import { AlphaNumeric } from '../dataElements/AlphaNumeric.js';
3
+ import { DataGroup } from '../dataGroups/DataGroup.js';
4
+ import { SegmentDefinition } from '../segmentDefinition.js';
5
+ import { BankIdentification } from '../dataGroups/BankIdentification.js';
6
+ /**
7
+ * General bank parameters
8
+ */
9
+ export class HIBPA extends SegmentDefinition {
10
+ static Id = this.name;
11
+ version = 3;
12
+ elements = [
13
+ new Numeric('bpdVersion', 1, 1, 3),
14
+ new BankIdentification('bank', 1, 1),
15
+ new AlphaNumeric('bankName', 1, 1, 60),
16
+ new Numeric('maxNumTransactions', 1, 1, 3),
17
+ new DataGroup('supportedLanguages', [new Numeric('lang', 1, 9, 3)], 1, 1),
18
+ new DataGroup('supportedHbciVersions', [new Numeric('version', 1, 9, 3)], 1, 1),
19
+ new Numeric('maxMessageSizeInKb', 0, 1, 4),
20
+ new Numeric('minTimeoutSecs', 0, 1, 4),
21
+ new Numeric('maxTimeoutSecs', 0, 1, 4),
22
+ ];
23
+ }
@@ -0,0 +1,13 @@
1
+ import { Binary } from '../dataElements/Binary.js';
2
+ import { SegmentDefinition } from '../segmentDefinition.js';
3
+ /**
4
+ * Account transactions within period response
5
+ */
6
+ export class HIKAZ extends SegmentDefinition {
7
+ static Id = this.name;
8
+ version = 7;
9
+ elements = [
10
+ new Binary('bookedTransactions', 1, 1, Number.MAX_SAFE_INTEGER),
11
+ new Binary('notedTransactions', 0, 1, Number.MAX_SAFE_INTEGER),
12
+ ];
13
+ }
@@ -0,0 +1,13 @@
1
+ import { YesNo } from '../dataElements/YesNo.js';
2
+ import { Numeric } from '../dataElements/Numeric.js';
3
+ import { BusinessTransactionParameter } from './businessTransactionParameter.js';
4
+ /**
5
+ * Parameters for HKKAZ business transaction
6
+ */
7
+ export class HIKAZS extends BusinessTransactionParameter {
8
+ static Id = this.name;
9
+ version = 7;
10
+ constructor() {
11
+ super([new Numeric('maxDays', 1, 1, 4), new YesNo('entryCountAllowed', 1, 1), new YesNo('allAccountsAllowed', 1, 1, 5)], 6);
12
+ }
13
+ }
@@ -0,0 +1,11 @@
1
+ import { Text } from '../dataElements/Text.js';
2
+ import { AlphaNumeric } from '../dataElements/AlphaNumeric.js';
3
+ import { SegmentDefinition } from '../segmentDefinition.js';
4
+ /**
5
+ * Information to the customer of the bank
6
+ */
7
+ export class HIKIM extends SegmentDefinition {
8
+ static Id = this.name;
9
+ version = 2;
10
+ elements = [new AlphaNumeric('subject', 1, 1, 35), new Text('text', 1, 1, 2048)];
11
+ }
@@ -0,0 +1,23 @@
1
+ import { Numeric } from '../dataElements/Numeric.js';
2
+ import { AlphaNumeric } from '../dataElements/AlphaNumeric.js';
3
+ import { BankIdentification } from '../dataGroups/BankIdentification.js';
4
+ import { DataGroup } from '../dataGroups/DataGroup.js';
5
+ import { SegmentDefinition } from '../segmentDefinition.js';
6
+ /**
7
+ *
8
+ */
9
+ export class HIKOM extends SegmentDefinition {
10
+ static Id = this.name;
11
+ version = 4;
12
+ elements = [
13
+ new BankIdentification('bank', 1, 1),
14
+ new Numeric('defLang', 1, 1, 3),
15
+ new DataGroup('comParams', [
16
+ new Numeric('service', 1, 1, 2),
17
+ new AlphaNumeric('address', 1, 1, 512),
18
+ new AlphaNumeric('addressExt', 0, 1, 512),
19
+ new AlphaNumeric('filter', 0, 1, 3),
20
+ new Numeric('filterVer', 0, 1, 3),
21
+ ], 1, 1),
22
+ ];
23
+ }
@@ -0,0 +1,22 @@
1
+ import { YesNo } from '../dataElements/YesNo.js';
2
+ import { Numeric } from '../dataElements/Numeric.js';
3
+ import { AlphaNumeric } from '../dataElements/AlphaNumeric.js';
4
+ import { DataGroup } from '../dataGroups/DataGroup.js';
5
+ import { BusinessTransactionParameter } from './businessTransactionParameter.js';
6
+ /**
7
+ * Parameters for PIN/TAN method
8
+ */
9
+ export class HIPINS extends BusinessTransactionParameter {
10
+ static Id = this.name;
11
+ version = 1;
12
+ constructor() {
13
+ super([
14
+ new Numeric('minPinLen', 0, 1, 2),
15
+ new Numeric('maxPinLen', 0, 1, 2),
16
+ new Numeric('maxTanLen', 0, 1, 2),
17
+ new AlphaNumeric('textUserId', 0, 1, 30),
18
+ new AlphaNumeric('textCustomerId', 0, 1, 30),
19
+ new DataGroup('transactions', [new AlphaNumeric('transId', 1, 1, 6), new YesNo('tanRequired', 1, 1)], 0, 999),
20
+ ]);
21
+ }
22
+ }
@@ -0,0 +1,20 @@
1
+ import { Digits } from '../dataElements/Digits.js';
2
+ import { AlphaNumeric } from '../dataElements/AlphaNumeric.js';
3
+ import { DataGroup } from '../dataGroups/DataGroup.js';
4
+ import { SegmentDefinition } from '../segmentDefinition.js';
5
+ /**
6
+ * Responses to the message
7
+ */
8
+ export class HIRMG extends SegmentDefinition {
9
+ static Id = this.name;
10
+ static Version = 2;
11
+ version = HIRMG.Version;
12
+ elements = [
13
+ new DataGroup('answers', [
14
+ new Digits('code', 1, 1, 4),
15
+ new AlphaNumeric('refElement', 0, 1, 7),
16
+ new AlphaNumeric('text', 1, 1, 80),
17
+ new AlphaNumeric('params', 0, 10, 35),
18
+ ], 1, 99),
19
+ ];
20
+ }
@@ -0,0 +1,20 @@
1
+ import { Digits } from '../dataElements/Digits.js';
2
+ import { AlphaNumeric } from '../dataElements/AlphaNumeric.js';
3
+ import { DataGroup } from '../dataGroups/DataGroup.js';
4
+ import { SegmentDefinition } from '../segmentDefinition.js';
5
+ /**
6
+ * Responses to the message
7
+ */
8
+ export class HIRMS extends SegmentDefinition {
9
+ static Id = this.name;
10
+ static Version = 2;
11
+ version = HIRMS.Version;
12
+ elements = [
13
+ new DataGroup('answers', [
14
+ new Digits('code', 1, 1, 4),
15
+ new AlphaNumeric('refElement', 0, 1, 7),
16
+ new AlphaNumeric('text', 1, 1, 80),
17
+ new AlphaNumeric('params', 0, 10, 35),
18
+ ], 1, 99),
19
+ ];
20
+ }
@@ -0,0 +1,31 @@
1
+ import { Dat } from '../dataElements/Dat.js';
2
+ import { AlphaNumeric } from '../dataElements/AlphaNumeric.js';
3
+ import { InternationalAccountGroup } from '../dataGroups/InternationalAccount.js';
4
+ import { AccountGroup } from '../dataGroups/Account.js';
5
+ import { BalanceGroup } from '../dataGroups/Balance.js';
6
+ import { MoneyGroup } from '../dataGroups/Money.js';
7
+ import { Currency } from '../dataElements/Currency.js';
8
+ import { TimeStampGroup } from '../dataGroups/TimeStamp.js';
9
+ import { SegmentDefinition } from '../segmentDefinition.js';
10
+ /**
11
+ * Account balances response
12
+ */
13
+ export class HISAL extends SegmentDefinition {
14
+ static Id = this.name;
15
+ version = 8;
16
+ elements = [
17
+ new AccountGroup('account', 1, 1, 1, 6),
18
+ new InternationalAccountGroup('account', 1, 1, 7),
19
+ new AlphaNumeric('product', 1, 1, 30),
20
+ new Currency('currency', 1, 1),
21
+ new BalanceGroup('balance', 1, 1),
22
+ new BalanceGroup('notedBalance', 0, 1),
23
+ new MoneyGroup('creditLimit', 0, 1),
24
+ new MoneyGroup('availableAmount', 0, 1),
25
+ new MoneyGroup('usedAmount', 0, 1),
26
+ new MoneyGroup('overDraft', 0, 1, 6),
27
+ new TimeStampGroup('timestamp', 0, 1),
28
+ new Dat('dueDate', 0, 1),
29
+ new MoneyGroup('seizable', 0, 1, 8),
30
+ ];
31
+ }
@@ -0,0 +1,16 @@
1
+ import { Numeric } from '../dataElements/Numeric.js';
2
+ import { Identification } from '../dataElements/Identification.js';
3
+ import { SegmentDefinition } from '../segmentDefinition.js';
4
+ /**
5
+ * Synchonisation response
6
+ */
7
+ export class HISYN extends SegmentDefinition {
8
+ static Id = this.name;
9
+ version = 4;
10
+ elements = [
11
+ new Identification('systemId', 0, 1),
12
+ new Numeric('msgNr', 0, 1, 4),
13
+ new Numeric('secRefNrKey', 0, 1, 16),
14
+ new Numeric('secRefNrSignature', 0, 1, 16),
15
+ ];
16
+ }