1.0.0 • Published 4 years ago

@centrapay/swift-parser v1.0.0

Weekly downloads
335
License
Apache-2.0
Repository
github
Last release
4 years ago

Centrapay SWIFT Parser

SWIFT bank statement parser for JavaScript (ES2015). Supports MT 940 Customer Statement Message and MT 942 Interim Transaction Report.

Installation

npm install @centrapay/swift-parser

Usage

const parser = require('@centrapay/swift-parser');
const statements = parser.parse({
  type: 'mt940',
  data: fs.readFileSync(path, 'utf8'),
});

statements.forEach(stmt => {
  console.log(stmt.statementDate, stmt.accountIdentification, stmt.number.statement);
  stmt.transactions.forEach(txn => {
    console.log(txn.amount, txn.currency);
  };
};

CLI

This package also includes a CLI which parses a SWIFT file and outputs the result as JSON:

swift-parse -t mt942 my-statement.txt

API

parser.parse()

Parse a SWIFT statement document.

If parser.parse() is invoked with { validate: true } then MT940 statements are additionally validated for:

  • all strictly required tags
  • opening/closing balance currency is the same
  • opening balance + turnover = closing balance

Returns: Array\<Statement>

Params:

ParamTypeDescription
datastringraw SWIFT message text
typestringmessage format (mt940 or mt942)
validatebooleanOptional perform additional semantic error checking

Statement

FieldTypeDescription
transactionReferencestringtag 20 reference
relatedReferencestringtag 21 reference
accountIdentificationstringtag 25 own bank account identification
number.statementstringtag 28 main statement number
number.sequencestringtag 28 statement sub number (sequence)
number.sectionstringtag 28 statement sub sub number (present on some banks)
statementDateDatetag 62 (MT940, day precision) or tag 13D (MT942, minute precision)
openingBalanceDateDatetag 60 statement opening date
closingBalanceDateDatetag 62 statement closing date
closingAvailableBalanceDateDatetag 64 closing available balance date, default = closing date
forwardAvailableBalanceDateDatetag 65 forward available balance date, default = closing available date
currencystringstatement currency (USD, EUR ...)
openingBalanceBigNumberbeginning balance of the statement (with sign, based on debit/credit mark)
closingBalanceBigNumberending balance of the statement (with sign, based on debit/credit mark)
closingAvailableBalanceBigNumbertag 64 closing available balance, default = closing balance
forwardAvailableBalanceBigNumbertag 65 forward available balance, default = closing available
informationToAccountOwnerstringadditional statement level information
transactionsarraycollection of transactions
messageBlocksobjectstatement message blocks, if present (EXPERIMENTAL)

Transaction

FieldTypeDescription
dateDatetransaction date
amountBigNumbertransaction amount (with sign, Credit+, Debit-)
reversalBooleantransaction is a reversal
currencystringtransaction currency (copy of statement currency)
detailsstringcontent of relevant 86 tag(s), may be multiline (\n separated)
transactionTypestringMT940 transaction type code (e.g. NTRF ...)
referencestringpayment reference field
entryDateDateentry date field
fundsCodestringfunds code field
bankReferencestringbank reference
extraDetailsstringextra details (supplementary details)
structuredDetailsObjectstructured details if detected
nonSwiftstringcontent of NS tags associated with a transaction (after tags 61 or 86)

Structured Transaction Details

The transaction.structuredDetails attribute can be used to access structured data from statement transaction details (SWIFT "86" tag). The following structured detail formats are supported:

  • '<sep>DD', where <sep> can be '>' or '?' and DD is two digits
  • '/TAG/value', where TAG is 2 to 4 uppercase chars.

Example

>20some details >30more data
{
  "20": "some details",
  "30": "more data"
}

Example

/ORDP/Smith Corp
{
  "ORDP": "Smith Corp"
}

History

See Changelog

Legal

Copyright © 2015 Alexander Tsybulsky and other contributors. Copyright © 2020 Centrapay.

This software is licensed under Apache-2.0 License. Please see LICENSE for details.

Credits

Forked from a-fas/mt940. Originally inspired by WoLpH/mt940.