Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f727a2f

Browse files
committedJan 27, 2024
feat: initial build
0 parents  commit f727a2f

22 files changed

+4898
-0
lines changed
 

‎.eslintrc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"env": {
3+
"es2021": true,
4+
"node": true
5+
},
6+
"extends": [
7+
"airbnb-base",
8+
"eslint:recommended",
9+
"plugin:import/errors",
10+
"plugin:import/warnings",
11+
"plugin:import/typescript",
12+
"plugin:@typescript-eslint/recommended",
13+
"prettier"
14+
],
15+
"parser": "@typescript-eslint/parser",
16+
"parserOptions": {
17+
"ecmaVersion": 12,
18+
"sourceType": "module"
19+
},
20+
"plugins": ["@typescript-eslint/eslint-plugin", "prettier"],
21+
"rules": {
22+
"import/prefer-default-export": "off",
23+
"@typescript-eslint/no-inferrable-types": "off",
24+
"import/extensions": "off",
25+
"camelcase": "off",
26+
"prettier/prettier": 0,
27+
"no-console": "off"
28+
},
29+
"settings": {
30+
"import/resolver": {
31+
"typescript": {
32+
"alwaysTryTypes": true
33+
}
34+
}
35+
}
36+
}

‎.github/workflows/npm-publish.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2+
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
3+
4+
name: Node.js Package
5+
6+
on:
7+
release:
8+
types: [created]
9+
push:
10+
branches:
11+
- main
12+
pull_request:
13+
branches:
14+
- main
15+
16+
jobs:
17+
build:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v3
21+
- uses: actions/setup-node@v3
22+
with:
23+
node-version: 18
24+
- run: yarn ci
25+
26+
publish-npm:
27+
needs: build
28+
runs-on: ubuntu-latest
29+
steps:
30+
- uses: actions/checkout@v3
31+
- uses: actions/setup-node@v3
32+
with:
33+
node-version: 18
34+
registry-url: https://registry.npmjs.org/
35+
- run: yarn ci
36+
- run: |
37+
if [[ "${{ github.event.head_commit.message }}" =~ ^(docs:|chore:) ]]; then
38+
echo "Skipping npm publish due to commit message."
39+
else
40+
npm publish --access public
41+
fi
42+
env:
43+
NODE_AUTH_TOKEN: ${{secrets.npm_token}}

‎.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.env
2+
node_modules
3+
.build
4+
dist
5+
.vscode

‎.husky/commit-msg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
npx --no -- commitlint --edit

‎.husky/pre-commit

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
npx lint-staged
5+
yarn lint

‎.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
coverage

‎.prettierrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "all",
4+
"tabWidth": 4,
5+
"semi": true,
6+
"printWidth": 100
7+
}

‎commitlint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = { extends: ['@commitlint/config-conventional'] };

‎jest.config.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { Config } from 'jest';
2+
3+
const jestConfig: Config = {
4+
clearMocks: true,
5+
maxWorkers: 1,
6+
preset: 'ts-jest',
7+
testEnvironment: 'node',
8+
testMatch: ['**/src/**/*.test.ts'],
9+
moduleNameMapper: {
10+
'^@resolver/(.*)$': '<rootDir>/src/resolver/$1',
11+
'^@types/(.*)$': '<rootDir>/src/types/$1',
12+
},
13+
};
14+
15+
export default jestConfig;

‎package.json

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"name": "utxo-orderbook-sdk",
3+
"description": "",
4+
"version": "0.0.1",
5+
"license": "Apache-2.0",
6+
"main": "dist/cjs/index.js",
7+
"module": "dist/mjs/index.js",
8+
"exports": {
9+
".": {
10+
"import": "./dist/mjs/index.js",
11+
"require": "./dist/cjs/index.js"
12+
}
13+
},
14+
"author": {
15+
"name": "hinson",
16+
"email": "hinson@sidan.io"
17+
},
18+
"files": [
19+
"dist"
20+
],
21+
"keywords": [],
22+
"scripts": {
23+
"build": "rm -fr dist/* && tsc -p tsconfig.json && tsc -p tsconfig-cjs.json",
24+
"ci": "yarn && yarn lint && yarn build",
25+
"pub": "yarn ci && npm publish --access public",
26+
"lint": "eslint 'src/*.ts' --fix",
27+
"prepare": "husky install"
28+
},
29+
"dependencies": {
30+
"@meshsdk/core": "^1.5.11-beta.4",
31+
"@types/node": "^20.4.10",
32+
"axios": "^1.4.0"
33+
},
34+
"devDependencies": {
35+
"@commitlint/cli": "^17.4.3",
36+
"@commitlint/config-conventional": "^17.4.3",
37+
"@types/aws-lambda": "^8.10.114",
38+
"@types/jest": "^29.5.1",
39+
"@types/pg": "^8.10.2",
40+
"@typescript-eslint/eslint-plugin": "^5.59.1",
41+
"@typescript-eslint/parser": "^5.59.1",
42+
"commitlint": "^17.4.3",
43+
"eslint": "^8.39.0",
44+
"eslint-config-airbnb-base": "^15.0.0",
45+
"eslint-config-prettier": "^8.8.0",
46+
"eslint-import-resolver-typescript": "^3.6.0",
47+
"eslint-plugin-import": "^2.27.5",
48+
"eslint-plugin-prettier": "^4.2.1",
49+
"husky": "^8.0.3",
50+
"jest": "^29.5.0",
51+
"prettier": "^2.8.8",
52+
"ts-jest": "^29.1.0",
53+
"typescript": "^5.1.6"
54+
},
55+
"lint-staged": {
56+
"src/*.{js,ts,}": [
57+
"yarn prettier --write",
58+
"yarn eslint --fix"
59+
]
60+
}
61+
}

‎readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# UTxO Orderbook Typescript API

‎src/client/accounts/index.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { AxiosInstance } from 'axios';
2+
import {
3+
CreateAccountRequest,
4+
CreateAccountResponse,
5+
SignInRequest,
6+
SignInResponse,
7+
BuildDepositTransactionRequest,
8+
BuildDepositTransactionResponse,
9+
SubmitDepositTransactionRequest,
10+
SubmitDepositTransactionResponse,
11+
} from '../../types';
12+
13+
export class Accounts {
14+
private axiosInstance: AxiosInstance;
15+
16+
constructor(axiosInstance: AxiosInstance) {
17+
this.axiosInstance = axiosInstance;
18+
}
19+
20+
public create(data: CreateAccountRequest): Promise<CreateAccountResponse> {
21+
return this.axiosInstance.post('/accounts/create', data);
22+
}
23+
24+
public signIn(data: SignInRequest): Promise<SignInResponse> {
25+
return this.axiosInstance.post('/accounts/signin', data);
26+
}
27+
28+
public buildDepositTransaction(
29+
data: BuildDepositTransactionRequest,
30+
): Promise<BuildDepositTransactionResponse> {
31+
return this.axiosInstance.post('/accounts/deposit/build', data);
32+
}
33+
34+
public submitDepositTransaction(
35+
data: SubmitDepositTransactionRequest,
36+
): Promise<SubmitDepositTransactionResponse> {
37+
return this.axiosInstance.post('/accounts/deposit/submit', data);
38+
}
39+
}

‎src/client/index.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import axios, { AxiosInstance } from 'axios';
2+
import { ApiHeaders, AuthHeaders } from '../types';
3+
import { Accounts } from './accounts';
4+
5+
export class ApiClient {
6+
private axiosInstance: AxiosInstance;
7+
8+
public accounts: Accounts;
9+
10+
constructor(baseURL: string, { jwt, apiKey }: AuthHeaders) {
11+
const headers: ApiHeaders = {
12+
'Content-Type': 'application/json',
13+
};
14+
if (jwt) {
15+
headers.Authorization = jwt;
16+
}
17+
if (apiKey) {
18+
headers['X-API-KEY'] = apiKey;
19+
}
20+
this.axiosInstance = axios.create({
21+
baseURL,
22+
headers,
23+
});
24+
25+
this.accounts = new Accounts(this.axiosInstance);
26+
}
27+
}

‎src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './types';

‎src/types/auth.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export type AuthHeaders = {
2+
jwt?: string;
3+
apiKey?: string;
4+
};
5+
6+
export type ApiHeaders = {
7+
'Content-Type': string;
8+
Authorization?: string;
9+
'X-API-KEY'?: string;
10+
};

‎src/types/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from './requests';
2+
export * from './response';
3+
export * from './auth';

‎src/types/requests/index.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* eslint-disable import/no-extraneous-dependencies */
2+
import { Asset, TxInParameter } from '@meshsdk/core';
3+
4+
export type CreateAccountRequest = {
5+
wallet_address: string;
6+
};
7+
8+
export type SignInRequest = {
9+
wallet_address: string;
10+
};
11+
12+
export type BuildDepositTransactionRequest = {
13+
deposit_amount: Asset[];
14+
input_utxos: TxInParameter[];
15+
};
16+
17+
export type SubmitDepositTransactionRequest = {
18+
signed_tx: string;
19+
};

‎src/types/response/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export type SignInResponse = {
2+
token: string;
3+
};
4+
5+
export type CreateAccountResponse = {
6+
message: string;
7+
};
8+
9+
export type BuildDepositTransactionResponse = {
10+
tx_hex: string;
11+
};
12+
13+
export type SubmitDepositTransactionResponse = {
14+
tx_hash: string;
15+
};

‎tsconfig-base.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"compilerOptions": {
3+
"allowJs": true,
4+
"allowSyntheticDefaultImports": true,
5+
"baseUrl": "src",
6+
"declaration": true,
7+
"esModuleInterop": true,
8+
"inlineSourceMap": false,
9+
"lib": ["esnext"],
10+
"listEmittedFiles": false,
11+
"listFiles": false,
12+
"moduleResolution": "node",
13+
"noFallthroughCasesInSwitch": true,
14+
"pretty": true,
15+
"resolveJsonModule": true,
16+
"rootDir": "src",
17+
"skipLibCheck": true,
18+
"strict": true,
19+
"traceResolution": false,
20+
"types": ["node", "jest"]
21+
},
22+
"compileOnSave": false,
23+
"exclude": ["node_modules", "dist"],
24+
"include": ["src"]
25+
}

‎tsconfig-cjs.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "./tsconfig-base.json",
3+
"compilerOptions": {
4+
"module": "commonjs",
5+
"outDir": "dist/cjs",
6+
"target": "es2015"
7+
}
8+
}

‎tsconfig.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "./tsconfig-base.json",
3+
"compilerOptions": {
4+
"module": "esnext",
5+
"outDir": "dist/mjs",
6+
"target": "esnext"
7+
}
8+
}

‎yarn.lock

Lines changed: 4563 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.