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: 0 additions & 2 deletions .env

This file was deleted.

3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/__mocks__/**/*.ts
**/*.d.ts
**/*.test.ts
30 changes: 30 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = {
env: {
es2021: true,
node: true
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'prettier'
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 12,
sourceType: 'module',
project: ['./tsconfig.json'],
files: ['*.ts']
},
plugins: [
'@typescript-eslint'
],
root: true,
rules: {
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/ban-ts-comment': 'warn',
'@typescript-eslint/no-var-requires': 'error',
'max-len': ['error', { "code": 120, "ignoreUrls": true, ignorePattern: '^import .*' }]
}
};
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,12 @@
/package-lock.json
/tmp
node_modules
*.json
*.jsonl
!package.json
!tsconfig.json
!.prettierrc.json
.env
tsconfig.tsbuildinfo
coverage/
.DS_Store
12 changes: 12 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# You can override the included template(s) by including variable overrides
# SAST customization: https://docs.gitlab.com/ee/user/application_security/sast/#customizing-the-sast-settings
# Secret Detection customization: https://docs.gitlab.com/ee/user/application_security/secret_detection/#customizing-settings
# Dependency Scanning customization: https://docs.gitlab.com/ee/user/application_security/dependency_scanning/#customizing-the-dependency-scanning-settings
# Note that environment variables can be set in several places
# See https://docs.gitlab.com/ee/ci/variables/#cicd-variable-precedence
stages:
- test
sast:
stage: test
include:
- template: Security/SAST.gitlab-ci.yml
7 changes: 7 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"trailingComma": "es5",
"printWidth": 120,
"tabWidth": 4,
"semi": true,
"singleQuote": true
}
163 changes: 121 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ Tapjaw example
Example of the Tapjaw implementation

- [Tapjaw example](#tapjaw-example)
- [Primary Dependencies](#primary-dependencies)
- [Install](#install)
- [Usage](#usage)
- [Extending the example with the TapjawGenerator](#extending-the-example-with-the-tapjawgenerator)
- [Tutorial](#tutorial)
- [Setup new project](#setup-new-project)
- [Command Implementation](#command-implementation)
- [Setting up and managing commands](#setting-up-and-managing-commands)
- [Introduction](#introduction)
- [Implementation](#implementation)
- [Setup class](#setup-class)
- [Setup methods and properties](#setup-methods-and-properties)
- [Connector Implementation](#connector-implementation)
Expand All @@ -24,6 +26,15 @@ Example of the Tapjaw implementation
- [Creating your own configuration](#creating-your-own-configuration)
- [Overriding the TapjawMessage](#overriding-the-tapjawmessage)


# Primary Dependencies

- TapjawImporter - The main library which provides the schemas, interfaces and contract for creating adapters, commands, messages, iterators and connectors.
- Commander - We use commander as the foundation to our command line interface paradigm.
- Inversify - We use inversify to manage the DI/IoC for adapters, connectors, configurations and third party modules.
- Luxon - Luxon is a replacement to moment.js, inside `src/modules/date` you will find our standard palette of commonly used date functions.
- Dotenv - Loads the `.env` file, which the values are read by with `src/config` classes and are injected into the DI/IoC for use across the application.

# Install

Download the project.
Expand All @@ -32,11 +43,16 @@ Download the project.
$ git clone https://github.com/digidip/tapjaw-example.git
```

Install the project's dependancies.
Install the project dependancies.

```bash
$ cd tapjaw-example

$ yarn install

...will take a few moments

$ yarn tsc
```

Start example API server.
Expand All @@ -50,66 +66,129 @@ $ yarn server
To perform a basic GET request, execute:

```bash
$ bin/run hello
get Animals
{"signature":"70e3baf7f7db6ed793f7837008e1a7e608adfcf95ce07eb02544d835e9a879e9","sourceProviderName":"animals","import_date":"2019-09-18T09:12:35.732Z","payload":{"type":"Dog"}}
{"signature":"55964a867bacb5169869498db99b68e7d2b0bfcc5dfec4d4456626674992089c","sourceProviderName":"animals","import_date":"2019-09-18T09:12:35.732Z","payload":{"type":"Cat"}}
{"signature":"f1678214e62aae890c6ffaa0cd3c9154e086b80d3c292fef0610163a6d8979b7","sourceProviderName":"animals","import_date":"2019-09-18T09:12:35.733Z","payload":{"type":"Narwhal"}}
{"signature":"114f6721e0e2f17b68be5caaac4391193c5b0edc409e8c9b6cd5ee3e8d4097b7","sourceProviderName":"animals","import_date":"2019-09-18T09:12:35.733Z","payload":{"type":"Komodo Dragon"}}
{"signature":"47b9e7f65611be13ea7df2476eb53036eddcbdf4c344eb7474076bca7d4601cd","sourceProviderName":"animals","import_date":"2019-09-18T09:12:35.733Z","payload":{"type":"Wasp"}}
{"signature":"9caaef5435ad411ef97ccf5ed3107a36ade6d3420bfc3c9a4d267390cf058a3f","sourceProviderName":"animals","import_date":"2019-09-18T09:12:35.733Z","payload":{"type":"Ladybird"}}
$ bin/run apis tapjaw-example -i test
{"signature":"819b118f0139bcf6b7f5426d8cd4793bcade306f7f8941f1bb59d972ea48a822","sourceProviderName":"tapjaw-example merchant","import_date":"2021-11-03T15:26:20.315Z","payload":{"name":"henry"},"importId":"test","networkName":"tapjaw-example"}
{"signature":"16b27dc0da3b8272c29350935151ab8371fb3452018fdc83cfcaf383bcfe6360","sourceProviderName":"tapjaw-example merchant","import_date":"2021-11-03T15:26:20.339Z","payload":{"name":"james"},"importId":"test","networkName":"tapjaw-example"}
{"signature":"8c577e250986393fa78192443bf34b4a14df935d9a3addb3888e2e24516f4f11","sourceProviderName":"tapjaw-example merchant","import_date":"2021-11-03T15:26:20.358Z","payload":{"name":"sasha"},"importId":"test","networkName":"tapjaw-example"}
{"signature":"47551f3acef29f5a31d05b3931a0a126fb773ed5a816c87d288072774a192138","sourceProviderName":"tapjaw-example merchant","import_date":"2021-11-03T15:26:20.380Z","payload":{"name":"pancho"},"importId":"test","networkName":"tapjaw-example"}
{"signature":"2f2170dcb6bb01bfb66ac5b15386c022afdabedd6efb10cbbf8fd540aa7e5db2","sourceProviderName":"tapjaw-example merchant","import_date":"2021-11-03T15:26:20.402Z","payload":{"name":"errin"},"importId":"test","networkName":"tapjaw-example"}
{"signature":"85256934bb44a200b6c745e84afc608284d1e4725417eceab2901e885a0f70f7","sourceProviderName":"tapjaw-example merchant","import_date":"2021-11-03T15:26:20.423Z","payload":{"name":"lorna"},"importId":"test","networkName":"tapjaw-example"}
{"signature":"ad7202fb1c71b44df19d02dc47587f898f966d7addd2289b84c51b7a09e8ec0c","sourceProviderName":"tapjaw-example merchant","import_date":"2021-11-03T15:26:20.444Z","payload":{"name":"rosa"},"importId":"test","networkName":"tapjaw-example"}
{"signature":"0677dd63d9ee11f2a6d1def6a5e70f725b0f3bb1766db0f7b84e5bbc06d57a0a","sourceProviderName":"tapjaw-example merchant","import_date":"2021-11-03T15:26:20.464Z","payload":{"name":"biggles"},"importId":"test","networkName":"tapjaw-example"}
```

To perform a basic POST request, execute:
```bash
$ bin/run tools hello "Hello from Tapjaw" --name="Pancho"
Hello World...Pancho has something to say: Hello from Tapjaw
```

# Tutorial

## Setup new project

1. Checkout this project to your local machine with `$ git clone https://github.com/digidip/tapjaw-example.git my-project`.
2. Change into the my-project directory with `$ cd my-project/`.
3. Delete the exist `.git/` directory with `$ rm -rf .git`. Additionally you can then perform `git init` to start your own repository.
4. Install dependencies with `$ yarn install`
5. Build project with `$ yarn tsc`, you should now be able to execute `$ bin/run` which will display the help screen by default.

## Setting up and managing commands

### Introduction

We've created two example commands, a simple `src/commands/tools/hello.ts` command, and an API featured command at `src/commands/apis/tapjaw-example.ts`.

You can see which available API commands exist by executing:

```bash
$ bin/run hello --post
post Animals
{"signature":"70e3baf7f7db6ed793f7837008e1a7e608adfcf95ce07eb02544d835e9a879e9","sourceProviderName":"animals","import_date":"2019-09-18T09:12:35.732Z","payload":{"type":"Dog"}}
{"signature":"55964a867bacb5169869498db99b68e7d2b0bfcc5dfec4d4456626674992089c","sourceProviderName":"animals","import_date":"2019-09-18T09:12:35.732Z","payload":{"type":"Cat"}}
{"signature":"f1678214e62aae890c6ffaa0cd3c9154e086b80d3c292fef0610163a6d8979b7","sourceProviderName":"animals","import_date":"2019-09-18T09:12:35.733Z","payload":{"type":"Narwhal"}}
{"signature":"114f6721e0e2f17b68be5caaac4391193c5b0edc409e8c9b6cd5ee3e8d4097b7","sourceProviderName":"animals","import_date":"2019-09-18T09:12:35.733Z","payload":{"type":"Komodo Dragon"}}
{"signature":"47b9e7f65611be13ea7df2476eb53036eddcbdf4c344eb7474076bca7d4601cd","sourceProviderName":"animals","import_date":"2019-09-18T09:12:35.733Z","payload":{"type":"Wasp"}}
{"signature":"9caaef5435ad411ef97ccf5ed3107a36ade6d3420bfc3c9a4d267390cf058a3f","sourceProviderName":"animals","import_date":"2019-09-18T09:12:35.733Z","payload":{"type":"Ladybird"}}
$ bin/run help apis
Usage: run apis [options] [command] <api>

Execute an API command

Options:
-h, --help display help for command

Commands:
tapjaw-example [options] TapjawExample API Command
help [command] display help for command
```

To perform a basic GET request with a limit, execute:
or you can also see which tool commands exist by executing:

```bash
$ bin/run hello --limit=2
get Animals
{"signature":"70e3baf7f7db6ed793f7837008e1a7e608adfcf95ce07eb02544d835e9a879e9","sourceProviderName":"animals","import_date":"2019-09-18T09:12:35.732Z","payload":{"type":"Dog"}}
{"signature":"55964a867bacb5169869498db99b68e7d2b0bfcc5dfec4d4456626674992089c","sourceProviderName":"animals","import_date":"2019-09-18T09:12:35.732Z","payload":{"type":"Cat"}}
$ bin/run help tools
Usage: run tools [options] [command] <tool>

Execute a tool command

Options:
-h, --help display help for command

Commands:
hello [options] <caption> A hello demo command
help [command] display help for command
```

To perform a basic GET request with Basic Authentication, execute:
To see what features the `$ bin/run tools hello` command provides, additonally and example of it's usage execute:

```bash
$ bin/run hello-secure test test
get Animals (secure call)
{"signature":"70e3baf7f7db6ed793f7837008e1a7e608adfcf95ce07eb02544d835e9a879e9","sourceProviderName":"animals","import_date":"2019-09-18T09:12:35.732Z","payload":{"type":"Dog"}}
{"signature":"55964a867bacb5169869498db99b68e7d2b0bfcc5dfec4d4456626674992089c","sourceProviderName":"animals","import_date":"2019-09-18T09:12:35.732Z","payload":{"type":"Cat"}}
{"signature":"f1678214e62aae890c6ffaa0cd3c9154e086b80d3c292fef0610163a6d8979b7","sourceProviderName":"animals","import_date":"2019-09-18T09:12:35.733Z","payload":{"type":"Narwhal"}}
{"signature":"114f6721e0e2f17b68be5caaac4391193c5b0edc409e8c9b6cd5ee3e8d4097b7","sourceProviderName":"animals","import_date":"2019-09-18T09:12:35.733Z","payload":{"type":"Komodo Dragon"}}
{"signature":"47b9e7f65611be13ea7df2476eb53036eddcbdf4c344eb7474076bca7d4601cd","sourceProviderName":"animals","import_date":"2019-09-18T09:12:35.733Z","payload":{"type":"Wasp"}}
{"signature":"9caaef5435ad411ef97ccf5ed3107a36ade6d3420bfc3c9a4d267390cf058a3f","sourceProviderName":"animals","import_date":"2019-09-18T09:12:35.733Z","payload":{"type":"Ladybird"}}
$ bin/run tools help hello
Usage: run tools hello [options] <caption>

A hello demo command

Arguments:
caption A simple caption

Options:
-n, --name <string> Add a name to the message
-h, --help display help for command

Examples:
$ bin/mmt tools hello "My super caption" --name="Sasha"
```
### Implementation

Generally a tapjaw project contains four distinct command types, these are:

- `src/commands/apis/...` API to Messages Commands (uses `STDOUT`)

*API commands* are used exclusively for querying APIs and transforming the response to a standardised message which gets written to a `STDOUT` buffer as a JSON string. API commands employ an adapter along with one more more connectors, and iterator to complete this task.


- `src/commands/filters/...` Messages filter Commands (uses `STDIN`/`STDOUT`)

*Filter commands* are used to read in JSON messages from the `STDIN` buffer, then filter out messages which should be ignored (for some business related reason), or written to the filter's `STDOUT` buffer.


- `src/commands/stores/...` Messages storing Commands (uses `STDIN`)

*Store commands* read from the `STDIN` buffer and should be designed to write to a third party service, database
storage, document storage or queue.


- `src/commands/tools/...` Additional tool commands. (uses `STDIN`/`STDOUT`)

*Tool comamnds* are free to perform any necassary purpose required in the project, which does not fit within the sccope of the 3 previous command types.

For example, tools can be used for creating a buffer splitting command, which reads messages from the `STDIN` buffer and then divides the messages with a modular calcuation and pipes each respective message to one of the two `STDOUT` commands. Additionally you may wish to output the same message into two different Store commands.



> ========= ========= ========= BLOCK!! ========= ========= ========= =========





# Extending the example with the TapjawGenerator

If you wish to experiment with this example, consider using the [TapjawGenerator](https://www.npmjs.com/package/generator-tapjaw) to add configs, connectors, adapters, commands or message contracts to the current project.

# Tutorial

## Setup new project

Please refer to the [TapjawGenerator](https://www.npmjs.com/package/generator-tapjaw) for further instructions.

## Command Implementation

Now the fun starts, you need to either edit or create a new command in the projects `src/commands` directory.

By default, we've created a `src/commands/hello.ts` class, so for this tutorial we'll use this class.

### Setup class

Expand Down
42 changes: 0 additions & 42 deletions api/basic-authentication.ts

This file was deleted.

Loading