This repository holds the code for the THX API project. A REST API that can be used to interact the the THX Smart Contract layer and which main purpose is to make it easier for developers to utilize blockchain technology in their applications.
- Prerequisites
- Installing
- Usage
- Testing
- Register clients
- Interface
- Database Schema Migration
- Docker
- NVM
We use docker to run our dependencies like mongo and ganache in. We run the development server locally, managing a common node version using Node Version Manager. You can also manually install the correct node version but usage of NVM is recommended.
# 1. Install/activate current nodejs defined in .nvmrc
nvm use
# 2. Provide environment variables
cp .env.example .env
# 3. Checkout SCSS submodule
git submodule init
git submodule update
# 4. Install packages
npm install --ci
# 5. Start working (docker compose up -d && npm run watch:debug)
npm run dev
# 6. shut down dependencies
docker compose down
The thx_mainnet and thx_testnet containers will start with prefilled wallets and all required contracts will be deployed automatically.
# Run e2e tests
npm run test
POST http://localhost:3000/reg
{
"application_type": "web",
"client_name": "Your App",
"grant_types": ["client_credentials"],
"redirect_uris": [],
"response_types": [],
"scope": "openid admin"
}
POST http://localhost:3000/reg
{
"application_type": "web",
"client_name": "THX Wallet",
"grant_types": ["authorization_code"],
"redirect_uris": ["https://dev.wallet.thx.network/signin-oidc"],
"post_logout_redirect_uris": ["https://dev.wallet.thx.network"],
"response_types": ["code"],
"scope": "openid user email offline_access"
}
Swagger Documentation is provided in the controllers of the routes and lives at the following endpoints:
npm run migrate:create name-of-my-script
A new file will be created inside migrations folder with a corresponding timestamp.
|_ migrations/
|- 20210108114324-name-of-my-script.js
Considering we want to add a quantity property to the products collection, the migration could be as follows:
export = {
async up(db: Db) {
return db.collection('products').updateMany({}, { $set: { quantity: 10 } });
},
async down(db: Db) {
return db.collection('products').updateMany({}, { $unset: { quantity: null } });
},
};
To get the migration status
npm run migrate:status
To run your migrations, simply run the command
npm run migrate:db
To rollback a migration use the down command
npm run migrate:undo-last