Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"describe": false,
"it": false,
"before": false
},
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ examples/out/
node_modules/
.DS_Store
*.iml
captor-swift-mock-*.tgz
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ node_modules/*
.eslintignore
.eslintrc
.gitignore
.vscode
.travis.yml
examples
captor-swift-mock-*.tgz
18 changes: 18 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"cSpell.words": [],
"editor.formatOnSave": true,
"explorer.autoRevealExclude": {
"**/node_modules": false
},
"git.openRepositoryInParentFolders": "always",
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
88 changes: 62 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
This is a fork of https://github.com/APshenkin/swift-mock with a few patches. Use at own risk.

# SWIFT Mock
JavaScript SWIFT mock that can emulate SWIFT network, parse and generate SWIFT [ISO 15022](http://www.iso15022.org/) messages. Swift parser was taked from [swift-parser](https://github.com/pstodulka/swift-parser), but it was refactored (moving to ES6 syntax, update API). Mock and message generator were created from scratch.

[![Test Status](https://travis-ci.org/APshenkin/swift-mock.svg?branch=master)](https://travis-ci.org/APshenkin/swift-mock)
JavaScript SWIFT mock that can emulate SWIFT network, parse and generate SWIFT [ISO 15022](http://www.iso15022.org/) messages. Swift parser was taked from [swift-parser](https://github.com/pstodulka/swift-parser), but it was refactored (moving to ES6 syntax, update API). Mock and message generator were created from scratch.

## Features
* parse FIN MT message defined by the [ISO 15022](http://www.iso15022.org/) standard
* generate FIN MT messages
* emulate SWIFT network

- parse FIN MT message defined by the [ISO 15022](http://www.iso15022.org/) standard
- generate FIN MT messages
- emulate SWIFT network

## Limitations
* cannot parse field `77E` - message _MT n98 Proprietary Message_

- cannot parse field `77E` - message _MT n98 Proprietary Message_

## Installation

```Shell
$ npm install --save swift-mock
$ npm install --save @captor/swift-mock
```

## Usage

```JavaScript
const Swift = require('swift-mock');
const Swift = require('@captor/swift-mock');

const swift = new Swift();

Expand Down Expand Up @@ -52,21 +57,24 @@ swift.run();
## API

### new SwiftParser([options])

Initializes a new instance of `SWIFT Mock` using given metadata. If `metadata` is omitted, the default metadata is used.

#### options Parameters

* `in` - folder, from where mock will take messages (default: `./in`)
* `out` - folder, where mock will store answers for messages (default: `./out`)
* `logLevel` - logging level (default: 0)
* `fieldPatterns` - path to block 4 field patterns
* `saveIncomingMessages` - save parsed incoming messages in memory (default: `false`)
* `delete` - delete incoming messages after reading (default: `false`)
* `elastic` - format log messages in Elastic format or not (default: `false`)
* `persistent` - indicates whether the process should continue to run as long as files are being watched. (default: `true`)
- `in` - folder, from where mock will take messages (default: `./in`)
- `out` - folder, where mock will store answers for messages (default: `./out`)
- `logLevel` - logging level (default: 0)
- `fieldPatterns` - path to block 4 field patterns
- `saveIncomingMessages` - save parsed incoming messages in memory (default: `false`)
- `delete` - delete incoming messages after reading (default: `false`)
- `elastic` - format log messages in Elastic format or not (default: `false`)
- `persistent` - indicates whether the process should continue to run as long as files are being watched. (default: `true`)

### swift.parse(swift)

Parses the `swift` message. The line breaks of `swift` must be in Unix format (`\n`).

```
const Swift = require('./parser/swift');
const swift = new Swift();
Expand All @@ -78,7 +86,9 @@ const ast = swift.parse(file)
```

### swift.generate(data)

Generate swift message. data should be array of blocks. Blocks order will be the same as in array.

```
const Swift = require('./parser/swift');
const swift = new Swift();
Expand Down Expand Up @@ -153,7 +163,9 @@ const message = swift.generate([
Below are rules how to build blocks.

#### Block 1

Data should be a object with required fields or string

```
let block = {
block: 1, data: {
Expand All @@ -171,7 +183,9 @@ let block = 'F21RMSFGB2LAXXX0094002855'
```

#### Block 2

Data should be a object with required fields or string

```
let block = {
block: 2, data: {
Expand All @@ -194,7 +208,9 @@ let block = 'I502SOPPLULXXXXXN'
```

#### Block 3

Data should be an object with depth === 1

```
let block = {
block: 3, data: {
Expand All @@ -204,12 +220,15 @@ let block = {
```

#### Block 4

Data should be an object with depth === 1 or should be an array of fields in valid format.
There is two strategy to take values:
* content
* combine

- content
- combine

content:

```
let block = {
block: 4, data: {
Expand Down Expand Up @@ -260,7 +279,9 @@ let block = {
```

#### Block 5

Data should be an object with depth === 1

```
let block = {
block: 5, data: {
Expand All @@ -271,7 +292,9 @@ let block = {
```

#### Block S

Data should be an object with depth === 1

```
let block = {
block: 'S', data: {
Expand All @@ -283,12 +306,14 @@ let block = {

Values that are `undefined` will displays like this `{SAC:}`


### swift.on(predicate, callback)

Create a listener that will check incoming messages by predicate function and do callback.
For `swift.on` only first passed predicate will be applied
* predicate - function
* callback - function

- predicate - function
- callback - function

```
swift.on((msg) => {
return msg.block1.receivingLtId === 'RMSFGB2LAXXX' && msg.block2.msgType === '509'
Expand All @@ -305,8 +330,10 @@ swift.on((msg) => {
###swift.onEvery(predicate, callback)
Create a listener that will check incoming messages by predicate function and do callback.
For `swift.onEvery` every passed predicate will be applied
* predicate - function
* callback - function

- predicate - function
- callback - function

```
swift.on((msg) => {
return msg.block1.receivingLtId === 'RMSFGB2LAXXX' && msg.block2.msgType === '509'
Expand All @@ -321,10 +348,12 @@ swift.on((msg) => {
```

### swift.send(message, outPath)

Place swift message to outPath folder. Message could be a string or array of blocks.
* message - string or array of blocks
* filenamePrefix - outgoing filename prefix (default: '');
* outPath - output folder path (default: `this.outputFolder`);

- message - string or array of blocks
- filenamePrefix - outgoing filename prefix (default: '');
- outPath - output folder path (default: `this.outputFolder`);

```
swift.send([
Expand Down Expand Up @@ -354,22 +383,29 @@ swift.send([
```

### swift.run()

Start swift listener

### swift.close()

Stop swift listener

### swift.cleanMessages()

Clean saved incoming messages

### swift.getMessages()

Get incoming messages

### swift.cleanListeners()

Clean listeners

## Current State

swift-mock is in its early days. Any feedback, issues, and pull requests are welcome.

## License

MIT © [Apshenkin](https://github.com/APshenkin)
Loading