Skip to content

Commit

Permalink
feat: schema translation for fspiop and fspiop20022
Browse files Browse the repository at this point in the history
feat: schema translation for fspiop and fspiop20022
  • Loading branch information
oderayi authored Oct 14, 2024
2 parents ae9d03c + ae89149 commit 6b02250
Show file tree
Hide file tree
Showing 42 changed files with 14,668 additions and 18,114 deletions.
3 changes: 1 addition & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ workflows:
- setup
filters:
tags:
only: /.*/
ignore: /v[0-9]+(\.[0-9]+)*\-snapshot+((\.[0-9]+)?)/
branches:
ignore:
- /feature*/
Expand Down Expand Up @@ -569,7 +569,6 @@ workflows:
- pr-tools/pr-title-check
- test-lint
- test-unit
- test-coverage
- vulnerability-check
- audit-licenses
filters:
Expand Down
6 changes: 1 addition & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,11 @@ module.exports = {
semi: ['error'],
},
env: {
node: true,
jest: true,
node: true
},
overrides: [
{
files: ['test/**/*.ts'],
env: {
jest: true,
},
rules: {
// add here any rules specific to test files
},
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,6 @@ devspace*
# Add Ignores
*IGNORE*
*ignore*
test/reports

.DS_Store
1 change: 1 addition & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
npm run lint
npm run dep:check
npm run audit:check
npm run test:unit
17 changes: 0 additions & 17 deletions .nycrc.yaml

This file was deleted.

155 changes: 107 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,78 +1,137 @@
# Typescript Project Template
# ML Schema Transformer (MLST)

<!-- ACTION: REPLACE <repo-name> placeholders in this document -->
[![Git Commit](https://img.shields.io/github/last-commit/mojaloop/<repo-name>.svg?style=flat)](https://github.com/mojaloop/<repo-name>/commits/master)
[![Git Releases](https://img.shields.io/github/release/mojaloop/<repo-name>.svg?style=flat)](https://github.com/mojaloop/<repo-name>/releases)
[![Npm Version](https://img.shields.io/npm/v/@mojaloop/<repo-name>.svg?style=flat)](https://www.npmjs.com/package/@mojaloop/<repo-name>)
[![NPM Vulnerabilities](https://img.shields.io/snyk/vulnerabilities/npm/@mojaloop/<repo-name>.svg?style=flat)](https://www.npmjs.com/package/@mojaloop/<repo-name>)
[![CircleCI](https://circleci.com/gh/mojaloop/<repo-name>.svg?style=svg)](https://circleci.com/gh/mojaloop/<repo-name>)
[![Git Commit](https://img.shields.io/github/last-commit/mojaloop/ml-schema-transformer-lib.svg?style=flat)](https://github.com/mojaloop/ml-schema-transformer-lib/commits/master)
[![Git Releases](https://img.shields.io/github/release/mojaloop/ml-schema-transformer-lib.svg?style=flat)](https://github.com/mojaloop/ml-schema-transformer-lib/releases)
[![Npm Version](https://img.shields.io/npm/v/@mojaloop/ml-schema-transformer-lib.svg?style=flat)](https://www.npmjs.com/package/@mojaloop/ml-schema-transformer-lib)
[![CircleCI](https://circleci.com/gh/mojaloop/ml-schema-transformer-lib.svg?style=svg)](https://circleci.com/gh/mojaloop/ml-schema-transformer-lib)

A project template for new mojaloop services and libraries that uses Typescript.
A shared component for transforming mojaloop payloads from one schema to another.

## Contributing

Refer to [CONTRIBUTING.md](./CONTRIBUTING.md) for information on how to contribute, committing changes, releases and snapshots.

<!-- ACTION: REPLACE THIS SECTION START -->
## Template Setup \<REMOVE SECTION\>
## Getting Started

This project provides a decent starting point for a new mojaloop library using typescript.
### Installing

<!-- NOTE: setup steps for this repo -->
1. Go to <https://github.com/new> to create a new repo
2. Select the "mojaloop/template-typescript-public" template
3. Find and replace all instances of `<repo-name>` globally across the whole project with your new project's name
4. Update the package name and version to match in `package.json`:
```
npm i @mojaloop/ml-schema-transformer-lib
```

### Usage

```json
"name": "@mojaloop/repo-name",
"version": "0.1.0",
...
```
MLST can be used via the exported facades or the creator function.

5. Copy the necessary circle ci config from the templates.
**Facades**

```bash
cp ./.circleci/config.example.yml ./.circleci/config.yml
rm -f ./.circleci/config.example.*
```
```
// ESM
import { TransformFacades } from '@mojaloop/ml-schema-transformer-lib';
// CJS
const { TransformFacades } = require('@mojaloop/ml-schema-transformer-lib')
// source is an FSPIOP POST /quotes payload
const source = {
body: {
quoteId: 'random quote id',
...,
},
headers: { ... },
params: { ... }
};
// target is an FSPIOP ISO 20022 Post /quotes payload
const target = await TransformFacades.FSPIOP.quotes.post(source);
```
The facade functions work with built-in mappings which are located in `src/mappings` directory.
The facade functions take optional second parameter of type `TransformFacadeOptions` for controlling certain aspects of the function.

If the project is a **Library**:
For example:
- To override the mapping used in the function, pass in `{ overrideMapping: 'your mapping JSON string' }`
- To pass in additional options for the instantiation of [MapTransform](https://github.com/integreat-io/map-transform) (the underlying transformation library), pass in `{ mapTransformOptions: { ...additionalMapTransformOptions } }`.
- To pass in additional options for the MapTransform mapper call, pass in `{ mapperOptions: { ...additionalMapperOptions } }`

Make sure to read comments and replace the applicable `publish` & `publish-snapshot` jobs with the NPM Publish job variants.
**Creator Function**

<!-- ACTION: REPLACE THIS SECTION END -->
```
// ESM
import { createTransformer } from ' @mojaloop/ml-schema-transformer-lib';
// CJS
const { createTransformer } = require('@mojaloop/ml-schema-transformer-lib')
## Pre-requisites
const mapping = { "quoteId": "CdtTrfTxInf.PmtId.TxId", ... }
### Install dependencies
const transformer = await createTransformer(mapping);
const transformer = createTransformer(mapping)
```bash
npm install
const source = { body: { quoteId: 'random quote id', ... }, ... };
const target = transformer.transform(source);
```

## Build
The `createTransform` function takes an optional second parameter of type `CreateTransformerOptions` for controlling the instantiation of the `MapTransform` object.

Command to transpile Typescript into JS:
For example:
- To pass in additional options for the instantiation of `MapTransform`, pass in { mapTransformOptions: { ...additionalMapTransformOptions } }

```bash
npm run build
```
### Custom Transform Functions

Command to LIVE transpile Typescript into JS live when any changes are made to the code-base:
Custom transform functions are special functions which are embedded in field mappings and are executed during transformation of those fields.
To provide custom transform functions (for both Facades and `createTransformer` use cases):

```bash
npm run watch
```
const fn1 = (options) => () => (data, state) => {
const modified = // apply custom transformation to `data`;
return modified;
}
const fn2 = (options) => () => (data, state) => {
const modified = // apply custom transformation to `data`;
return modified;
}
const options = {
mapTransformOptions: {
transformers: {
fn1,
fn2,
...
}
}
}
```

## Run
Replace `fn1` and `fn2` with the actual names of your functions. See `src/lib/transforms/index.ts` or [here](https://github.com/integreat-io/map-transform?tab=readme-ov-file#operations) for more on authoring and using custom transform functions in mappings.

```bash
npm start
```
### Environment Variables
| Env Variable Name | Default Value | Description |
|-----------------------------|---------------|------------------------------------------------------|
| MLST_LOG_LEVEL | `warn` | The log level for MLST |
| MLST_ILP_VERSION | `v4` | ILP version used for `ilpPacketToCondition` transform|


## Performance

## Tests
Hardware → Apple M3 Max, 14 Cores, 36 GB RAM

```bash
| Use Case | No. of Iterations | Duration |
|-------------------------------------------------|-------------------|----------------|
| POST /quotes transformation { FSPIOP → ISO } | 1000 | ~301ms |
| POST /quotes transformation { ISO → FSPIOP } | 1000 |~205ms |
| POST /transfers transformation { FSPIOP → ISO } | 1000 | ~135ms |
| POST /transfers transformation { ISO → FSPIOP } | 1000 | ~79ms |

## Development

### Install Depednencies

```
npm i
```

### Run Tests
```
npm test
```
```

### Build
```
npm run build
```
13 changes: 12 additions & 1 deletion audit-ci.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@
"moderate": true,
"allowlist": [ // NOTE: Please add as much information as possible to any items added to the allowList
// Currently no fixes available for the following
"GHSA-c2qf-rxjj-qqgw" // https://github.com/advisories/GHSA-c2qf-rxjj-qqgw
"GHSA-c2qf-rxjj-qqgw", // https://github.com/advisories/GHSA-c2qf-rxjj-qqgw
"GHSA-282f-qqgm-c34q", // https://github.com/advisories/GHSA-282f-qqgm-c34q
"GHSA-6vfc-qv3f-vr6c", // https://github.com/advisories/GHSA-6vfc-qv3f-vr6c
"GHSA-7fh5-64p2-3v2j", // https://github.com/advisories/GHSA-7fh5-64p2-3v2j
"GHSA-cgfm-xwp7-2cvr", // https://github.com/advisories/GHSA-cgfm-xwp7-2cvr
"GHSA-ghr5-ch3p-vcr6", // https://github.com/advisories/GHSA-ghr5-ch3p-vcr6
"GHSA-mjxr-4v3x-q3m4", // https://github.com/advisories/GHSA-mjxr-4v3x-q3m4
"GHSA-p9pc-299p-vxgp", // https://github.com/advisories/GHSA-p9pc-299p-vxgp
"GHSA-phwq-j96m-2c2q", // https://github.com/advisories/GHSA-phwq-j96m-2c2q
"GHSA-rjqq-98f6-6j3r", // https://github.com/advisories/GHSA-rjqq-98f6-6j3r
"GHSA-rm97-x556-q36h", // https://github.com/advisories/GHSA-rm97-x556-q36h
"GHSA-v88g-cgmw-v5xw" // https://github.com/advisories/GHSA-v88g-cgmw-v5xw
]
}
7 changes: 0 additions & 7 deletions jest.config.js

This file was deleted.

Loading

0 comments on commit 6b02250

Please sign in to comment.