# meridio-api

> ![Build Status](https://codebuild.us-east-1.amazonaws.com/badges?uuid=eyJlbmNyeXB0ZWREYXRhIjoiYmdJenNsQ2VONW5DTTcvWXJ2SG9GVTdWb1VEVXZ2OEVRZDV5MjhGUm9mcG9iUkhmU0tzbjRwa3BPdjNkY2pDeWFTMy9aMDhTVjJYOFlKOWpTeUdZdTdRPSIsIml2UGFyYW1ldGVyU3BlYyI6IkxaRmE2eFE4aUdYZ

Latest version **0.4.5** (published 2019-09-03) · UNLICENCED license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install meridio-api
pnpm add meridio-api
yarn add meridio-api
bun add meridio-api
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.4.5 |
| Published | 2019-09-03 |
| First published | 2019-09-03 |
| Weekly downloads | 0 |
| License | UNLICENCED |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.0.0 |
| Dependencies | 40 |
| Unpacked size | 3.2 MB |
| Known vulnerabilities | 0 (+39 in 7 direct dependencies) |
| Install scripts | no |
| Maintainers | evanstucker |

## Links

- npm: https://www.npmjs.com/package/meridio-api
- Repository: https://github.com/ConsenSys/pangea-backend
- Homepage: https://github.com/ConsenSys/pangea-backend#readme
- Issues: https://github.com/ConsenSys/pangea-backend/issues
- npm.io page: https://npm.io/package/meridio-api

## Dependencies (40)

- [pg](https://npm.io/package/pg.md) ^7.4.3
- [bull](https://npm.io/package/bull.md) ^3.4.3
- [cors](https://npm.io/package/cors.md) ^2.8.4
- [glob](https://npm.io/package/glob.md) ^7.1.3
- [path](https://npm.io/package/path.md) ^0.12.7
- [web3](https://npm.io/package/web3.md) ^1.0.0-beta.37
- [axios](https://npm.io/package/axios.md) ^0.18.0
- [raven](https://npm.io/package/raven.md) ^2.6.3
- [awilix](https://npm.io/package/awilix.md) ^3.0.9
- [dotenv](https://npm.io/package/dotenv.md) ^4.0.0
- [helmet](https://npm.io/package/helmet.md) ^3.13.0
- [morgan](https://npm.io/package/morgan.md) ^1.9.1
- [aws-sdk](https://npm.io/package/aws-sdk.md) ^2.209.0
- [express](https://npm.io/package/express.md) ^4.16.3
- [graphql](https://npm.io/package/graphql.md) ^14.1.1
- [nodemon](https://npm.io/package/nodemon.md) ~1.18.7
- [bluebird](https://npm.io/package/bluebird.md) ^3.5.1
- [coinbase](https://npm.io/package/coinbase.md) ^2.0.7
- [fast-csv](https://npm.io/package/fast-csv.md) ^2.4.1
- [passport](https://npm.io/package/passport.md) ^0.4.0
- [getstream](https://npm.io/package/getstream.md) ^3.19.0
- [sequelize](https://npm.io/package/sequelize.md) ~4.41.2
- [websocket](https://npm.io/package/websocket.md) ^1.0.28
- [mailgun-js](https://npm.io/package/mailgun-js.md) ^0.20.0
- [body-parser](https://npm.io/package/body-parser.md) ^1.18.2
- [finale-rest](https://npm.io/package/finale-rest.md) ^0.1.5
- [aws-xray-sdk](https://npm.io/package/aws-xray-sdk.md) ^2.1.0
- [bignumber.js](https://npm.io/package/bignumber.js.md) 7.0.2
- [jsonwebtoken](https://npm.io/package/jsonwebtoken.md) ^8.2.0
- [passport-jwt](https://npm.io/package/passport-jwt.md) ^4.0.0
- [accesscontrol](https://npm.io/package/accesscontrol.md) ^2.2.1
- [bcrypt-nodejs](https://npm.io/package/bcrypt-nodejs.md) ^0.0.3
- [sequelize-cli](https://npm.io/package/sequelize-cli.md) ^4.0.0
- [serve-favicon](https://npm.io/package/serve-favicon.md) ^2.4.5
- [passport-local](https://npm.io/package/passport-local.md) ^1.0.0
- [express-session](https://npm.io/package/express-session.md) ^1.15.6
- [@sendgrid/client](https://npm.io/package/@sendgrid/client.md) ^6.3.0
- [express-validator](https://npm.io/package/express-validator.md) ^4.3.0
- [graphql-type-json](https://npm.io/package/graphql-type-json.md) ^0.2.4
- [apollo-server-express](https://npm.io/package/apollo-server-express.md) ^2.4.8

## Recent versions

- 0.4.5 (latest) — 2019-09-03

## README

![Build Status](https://codebuild.us-east-1.amazonaws.com/badges?uuid=eyJlbmNyeXB0ZWREYXRhIjoiYmdJenNsQ2VONW5DTTcvWXJ2SG9GVTdWb1VEVXZ2OEVRZDV5MjhGUm9mcG9iUkhmU0tzbjRwa3BPdjNkY2pDeWFTMy9aMDhTVjJYOFlKOWpTeUdZdTdRPSIsIml2UGFyYW1ldGVyU3BlYyI6IkxaRmE2eFE4aUdYZ1RGOSsiLCJtYXRlcmlhbFNldFNlcmlhbCI6MX0%3D&branch=master)  

# Getting started

Our API requires the following environment variables to be stored in a **.env** file in the root directory. Contact a team member for sane defaults.

## Environmental Variables
* `SESSION_SECRET`: String for hashing passwords
* `SERVICE_SECRET`: String for hashing passwords
* `SALE_FACTORY_ADDRESS`: Address of the deployed Token Sale Factory Contract
* `PURCHASE_FACTORY_ADDRESS`: Address of the deployed Token Purchase Factory Contract
* `INFURA_PROJECT_ID`: API Key for the Infura Blockchain connection
* `S3_BUCKET`: Name of the S3 buckets for documents
* `S3_ENDPOINT`: For prod, this should be set to `img.meridio.co`, for all other environments should be set to `img-dev.meridio.co`
* `AWS_ACCESS_KEY_ID`: AWS Key ID for S3 bucket
* `AWS_SECRET_ACCESS_KEY`: AWS Key for S3 bucket
* `MAILGUN_API_KEY`: API for email sending
* `STREAM_API_KEY`: Stream Key for notifications
* `STREAM_API_SECRET`: Stream Secret
* `STREAM_API_APP_ID`: Stream App ID
* `ON_BOARDING_SECRET`: hashing for registration tokens
* `EMAIL_VERIFICATION_SECRET`: hashing email verification tokens
* `POSTGRES_HOST`: Hostname of your PostgresDB
* `POSTGRES_USER`: Username
* `POSTGRES_PW`: Password pw
* `POSTGRES_DB`: DB name
* `REDIS_PORT`: (optional) Port to connect to Redis, defaults to `6379`
* `REDIS_HOST`: (optional) Hostname of your Redis, defaults to `127.0.0.1`
* `REDIS_PASSWORD`: (optional) Password to connect to Redis, defaults to `NULL`
* `SENTRY_KEY`: (optional) Currently only reports uncaught errors
* `BLOCKCHAIN_ENV`: Currently supporting rinkeby, ropsten, mainnet, ganache
  
## Development Only
* `USER_EMAIL`: If you'd like to prepopulate your user's wallet address, enter in your email address here.
* `USER_ADDRESS_HASH`: If `USER_EMAIL` is found, this address hash will be added as a wallet for that user.
* `BLOCKCHAIN_SERVICE`: local blockchain service
* `SEQUELIZE_TIMEOUT`: (optional) SQL statement timeout (ms) override (default: 5000)
* `SEQUELIZE_LOGGING`: (optional) SQL logging options override (0 or 1, default 0, no sql logging);
* `HTTP_LOGGING`: (optional) Add apache style http logging via [Morgan](https://www.npmjs.com/package/morgan) - always on in development environments (0 or 1 when deployed, default 0, no http logging);


# Running the Full Stack Application
### Method 1: Docker Containers

To bring up the entire Meridio Application locally, run the following command:
```bash
npm run containers:full
```

This command uses relative paths, so you must also checkout the [frontend](https://github.com/MeridioRE/meridio-frontend) and [blockchain service](https://github.com/MeridioRE/meridio-blockchain-service) repositories as well.


# Running the API Stand Alone
### Method 1: Docker Containers

The first time you run the application you must first build the images  with the following command:
```bash
docker-compose build
```

Subsequent launches only require docker-compose up command.
```bash
docker-compose up
```

### Method 2: Host Operating System 
To run the application locally without docker, execute the following command:
```bash
npm run api-dev
```

# Development
### Development in Containers (with hot reload)
To simulate our production environment we use containers in development as well, reloading the application every time changes are detected in the the `api/` directory.

```bash
npm run containers:watch
```

# Testing
### Testing in Docker (with hot reload)
Similarly to the application hot reloading in the previous section, the following command will automatically rerun the test suite when it detects code changes.

```bash
npm run test:containers:watch
```

### Single Test Run in Docker 
To simulate a single run through the test suite use the following command. 
```bash
npm run test:containers
```

### Testing Locally
To test locally run the following command:
```bash
npm run test
```

# Libraries Used
* [Bull](https://github.com/OptimalBits/bull) - is a redis based queue for Node. It allows to create and manage job queues as the primary method of communication with the Blockchain Service.
* [Factory-girl](https://github.com/aexmachina/factory-girl) - For any given test, we need some data about which to make an assertion after performing some operation. This library is a fixture replacement with a [Sequelize](http://docs.sequelizejs.com/) interface. Please note using this package can introduce a DB dependency.
* [Finale](https://github.com/tommybananas/finale) - makes it easy to create flexible REST endpoints and controllers from Sequelize models in our Express app.
* [Mailgun](https://documentation.mailgun.com/en/latest/) - Email API for sending transactional emails from within our application.
* [Mocha with Chai](https://www.chaijs.com/) - is a feature-rich JavaScript test framework running on Node.js and in the browser, making asynchronous testing simple/ Mocha tests run serially, allowing for flexible and accurate reporting, while mapping uncaught exceptions to the correct test cases. 
* [Raven](https://github.com/getsentry/sentry-javascript/) - is an open source package from [Sentry](https://sentry.io) that helps developers monitor and fix crashes in real time.
* [Sequelize](http://docs.sequelizejs.com/)- is a promise-based ORM for Node.js v4 and up. It supports the dialects PostgreSQL, MySQL, SQLite and MSSQL and features solid transaction support, relations, read replication and more.
* [Sinon](https://sinonjs.org/) - is a standalone test spies, stubs and mocks for JavaScript. 
* [Stream](https://getstream.io/docs/) - allows us to build scalable news feeds & activity streams. This is currently utilized during our in-app notifications.

# Miscellaneous

### Postman
We use postman for teams for testing our API directly. For access to our library of prewritten tests, use the following [link](https://meridio.postman.co/collections/1512158-bef84538-5ca3-42e7-a524-afd48cb83311?workspace=61cd5349-e617-4009-8d04-05779d417cb0).

### Launch Exchange/Dai/Token Contracts locally

* Launch [Ganache](http://truffleframework.com/ganache/)
* `truffle compile`
* `truffle migrate --network development --reset`

## [API Documentation](https://uat-api.meridio.co/api/docs/)
## [DB Documentation](https://app.quickdatabasediagrams.com/#/schema/jfY1sYGzPEaOh10GSERkQg)

---
_Source: https://npm.io/package/meridio-api · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
