Skip to content

Commit

Permalink
Convert to Typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
lnbc1QWFyb24 committed Oct 23, 2019
1 parent de1ddad commit 06ad93e
Show file tree
Hide file tree
Showing 32 changed files with 8,038 additions and 1,725 deletions.
3 changes: 0 additions & 3 deletions .babelrc

This file was deleted.

20 changes: 10 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ jobs:
- checkout
- restore_cache:
keys:
- v1-dependencies-{{ checksum "package.json" }}
- v1-dependencies-
- v1-dependencies-{{ checksum "package.json" }}
- v1-dependencies-
- run: yarn
- run: yarn test
- run: yarn build
Expand All @@ -28,14 +28,14 @@ jobs:
- run: sudo npm i -g npm-cli-login
- run: NPM_USER=$NPM_USERNAME NPM_EMAIL=$NPM_EMAIL NPM_PASS=$NPM_PASSWORD npm-cli-login
- run: npm publish --dry-run
- run: gzip -9 ./dist/iife/sdk.js
- run: mv ./dist/iife/sdk.js.gz ./dist/iife/sdk.js
- run: gzip -9 /home/circleci/project/dist/bnc-sdk.umd.js
- run: mv /home/circleci/project/dist/bnc-sdk.umd.js.gz /home/circleci/project/dist/bnc-sdk.umd.js
- run: ls -al
- run: echo export VERSION=`awk '/version/{gsub(/("|",)/,"",$2);print $2};' package.json | sed 's/\./-/g'` >> $BASH_ENV
- run: mkdir /root/project/deploy-temp
- run: mkdir /root/project/deploy-temp/${VERSION}
- run: mv /root/project/dist/iife/*.js /root/project/deploy-temp/${VERSION}/
- run: aws s3 sync /root/project/deploy-temp/${VERSION}/ s3://staging.sdk.blocknative.com/${VERSION}/ --content-type "text/javascript" --content-encoding "gzip" --cache-control "max-age=31536000" --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers
- run: mkdir /home/circleci/project/deploy-temp
- run: mkdir /home/circleci/project/deploy-temp/${VERSION}
- run: mv /home/circleci/project/dist/*.js /home/circleci/project/deploy-temp/${VERSION}/
- run: aws s3 sync /home/circleci/project/deploy-temp/${VERSION}/ s3://staging.sdk.blocknative.com/${VERSION}/ --content-type "text/javascript" --content-encoding "gzip" --cache-control "max-age=31536000" --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers
deploy_prod:
docker:
- image: circleci/node:8.15-browsers
Expand All @@ -48,8 +48,8 @@ jobs:
- run: sudo npm i -g add npm-cli-login
- run: NPM_USER=$NPM_USERNAME NPM_EMAIL=$NPM_EMAIL NPM_PASS=$NPM_PASSWORD npm-cli-login
- run: npm publish
- run: gzip -9 ./dist/iife/sdk.js
- run: mv ./dist/iife/sdk.js.gz ./dist/iife/sdk.js
- run: gzip -9 /home/circleci/project/dist/bnc-sdk.umd.js
- run: mv /home/circleci/project/dist/bnc-sdk.umd.js.gz /home/circleci/project/dist/bnc-sdk.umd.js
- run: ls -al
- run: echo export VERSION=`awk '/version/{gsub(/("|",)/,"",$2);print $2};' package.json | sed 's/\./-/g'` >> $BASH_ENV
- run: mkdir /root/project/deploy-temp
Expand Down
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#root = true

[*]
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 100
indent_size = 2

[*.md]
trim_trailing_whitespace = false
8 changes: 0 additions & 8 deletions .eslintrc

This file was deleted.

12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
dist
node_modules
coverage
.nyc_output
.DS_Store
*.log
.vscode
.idea
dist
compiled
.awcache
.rpt2_cache
docs
.env
62 changes: 32 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ A lightweight JavaScript sdk to connect to the Blocknative backend Ethereum node

### Installation

```npm i bnc-sdk```
`npm i bnc-sdk`

### Quick Start

```javascript
import blocknativeSdk from "bnc-sdk"
import blocknativeSdk from 'bnc-sdk'

// create options object
const options = {
dappId: "Your dappId here",
networkId: "1",
transactionCallback: event => console.log(event.transaction)
dappId: 'Your dappId here',
networkId: '1',
transactionHandlers: [event => console.log(event.transaction)]
}

// initialize and connect to the api
Expand All @@ -33,16 +33,16 @@ const transaction = blocknative.transaction(hash)
const emitter = transaction.emitter

// listen to some events
emitter.on("txPool", transaction => {
emitter.on('txPool', transaction => {
console.log(`Sending ${transaction.value} wei to ${transaction.to}`)
})

emitter.on("txConfirmed", transaction => {
console.log("Transaction is confirmed!")
emitter.on('txConfirmed', transaction => {
console.log('Transaction is confirmed!')
})

// catch every other event that occurs and log it
emitter.on("all", transaction => {
emitter.on('all', transaction => {
console.log(`Transaction event: ${transaction.eventCode}`)
})
```
Expand All @@ -55,7 +55,7 @@ The following options object needs to be passed when initializing and connecting
const options = {
dappId: String,
networkId: String,
transactionCallback: Function,
transactionHandlers: Array,
ws: Function
}
```
Expand All @@ -74,19 +74,21 @@ The Ethereum network id that your application runs on. The following values are
- `'5'` Goerli Test Network
- `'42'` Kovan Test Network

#### `transactionCallback` - [OPTIONAL]
#### `transactionHandlers` - [OPTIONAL]

The function defined for the `transactionCallback` parameter will be called once for every status update for _every_ transaction that is associated with this connection on a watched address _or_ a watched transaction. This is useful as a global handler for all transactions and status updates. The callback is called with the following object:
An array of functions that will each be called once for every status update for _every_ transaction that is associated with this connection on a watched address _or_ a watched transaction. This is useful as a global handler for all transactions and status updates. Each callback is called with the following object:

```javascript
const options = {
// other options
transactionCallback: event => {
const {
transaction, // transaction object
emitterResult // data that is returned from the transaction event listener defined on the emitter
} = event
}
transactionHandlers: [
event => {
const {
transaction, // transaction object
emitterResult // data that is returned from the transaction event listener defined on the emitter
} = event
}
]
}
```

Expand All @@ -101,13 +103,13 @@ If you are running the sdk in a server environment, there won't be a native webs
#### (Client/Browser Environment)

```javascript
import blocknativeSdk from "bn-sdk"
import blocknativeSdk from 'bn-sdk'

// create options object
const options = {
dappId: "Your dappId here",
networkId: "1",
transactionCallback: event => console.log(event.transaction)
dappId: 'Your dappId here',
networkId: '1',
transactionHandlers: [event => console.log(event.transaction)]
}

// initialize and connect to the api
Expand All @@ -117,14 +119,14 @@ const blocknative = blocknativeSdk(options)
#### (Server/Node.js Environment)

```javascript
import blocknativeSdk from "bn-sdk"
import ws from "ws"
import blocknativeSdk from 'bn-sdk'
import ws from 'ws'

// create options object
const options = {
dappId: "Your dappId here",
networkId: "1",
transactionCallback: event => console.log(event.transaction),
dappId: 'Your dappId here',
networkId: '1',
transactionHandlers: [event => console.log(event.transaction)],
ws: ws
}

Expand Down Expand Up @@ -190,16 +192,16 @@ The emitter object is returned from calls to `account` and `transaction` and is

```javascript
// register a callback for a txPool event
emitter.on("txPool", transaction => {
console.log("Transaction is pending")
emitter.on('txPool', transaction => {
console.log('Transaction is pending')
})
```

The first parameter is the `eventCode` string of the event that you would like to register a callback for. For a list of the valid event codes, see the section on [event codes](#event-codes).

The second parameter is the callback that you would like to register to handle that event and will be called with a transaction object that includes all of the relevant details for that transaction. See the [Transaction Object](#transaction-object) section for more info on what is included.

Any data that is returned from the listener callback for `transaction` emitters will be included in the object that the global `transactionCallback` is called with under the `emitterResult` property.
Any data that is returned from the listener callback for `transaction` emitters will be included in the object that the global `transactionHandlers` functions will be called with under the `emitterResult` property.

#### Transaction Object

Expand Down
109 changes: 88 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,102 @@
"name": "bnc-sdk",
"version": "0.1.2",
"description": "SDK to connect to the blocknative backend via a websocket connection",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"keywords": [
"ethereum",
"websocket",
"blocknative",
"notifications"
],
"main": "dist/bnc-sdk.umd.js",
"module": "dist/bnc-sdk.es5.js",
"typings": "dist/types/bnc-sdk.d.ts",
"files": [
"dist/esm/*",
"dist/cjs/*"
"dist"
],
"types": "./types.d.ts",
"author": "Aaron Barnard <[email protected]>",
"repository": {
"type": "git",
"url": "https://github.com/blocknative/sdk"
},
"license": "MIT",
"engines": {
"node": ">=6.0.0"
},
"scripts": {
"lint": "tslint --project tsconfig.json -t codeFrame 'src/**/*.ts' 'test/**/*.ts'",
"prebuild": "rimraf dist",
"build": "tsc --module commonjs && rollup -c rollup.config.ts && typedoc --out docs --target es6 --theme minimal --mode file src",
"start": "rollup -c rollup.config.ts -w",
"test": "jest --coverage",
"test:watch": "jest --coverage --watch",
"test:prod": "npm run lint && npm run test -- --no-cache",
"deploy-docs": "ts-node tools/gh-pages-publish",
"report-coverage": "cat ./coverage/lcov.info | coveralls"
},
"jest": {
"transform": {
".(ts|tsx)": "ts-jest"
},
"testEnvironment": "node",
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"moduleFileExtensions": [
"ts",
"js"
],
"coveragePathIgnorePatterns": [
"/node_modules/",
"/test/",
"/src/"
],
"coverageThreshold": {
"global": {
"branches": 90,
"functions": 95,
"lines": 95,
"statements": 95
}
},
"collectCoverageFrom": [
"src/*.{js,ts}"
]
},
"prettier": {
"semi": false,
"singleQuote": true
},
"devDependencies": {
"@babel/core": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"babel-eslint": "^7.1.1",
"babel-plugin-external-helpers": "^6.18.0",
"eslint": "^4.1.1",
"@types/jest": "^23.3.2",
"@types/node": "^10.11.0",
"colors": "^1.3.2",
"coveralls": "^3.0.2",
"cross-env": "^5.2.0",
"jest": "^23.6.0",
"jest-config": "^23.6.0",
"lint-staged": "^8.0.0",
"lodash.camelcase": "^4.3.0",
"prettier": "^1.14.3",
"prompt": "^1.0.0",
"replace-in-file": "^3.4.2",
"rimraf": "^2.6.2",
"rollup": "^1.19.3",
"rollup-plugin-babel": "^4.3.3",
"rollup-plugin-commonjs": "^10.0.2",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-json": "^4.0.0",
"@joseph184/rollup-plugin-node-builtins": "^2.1.4",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-terser": "^5.1.1"
"rollup-plugin-sourcemaps": "^0.4.2",
"rollup-plugin-typescript2": "^0.24.3",
"semantic-release": "^15.9.16",
"shelljs": "^0.8.3",
"travis-deploy-once": "^5.0.9",
"ts-jest": "^23.10.2",
"ts-node": "^7.0.1",
"tslib": "^1.10.0",
"tslint": "^5.11.0",
"tslint-config-prettier": "^1.15.0",
"tslint-config-standard": "^8.0.1",
"typedoc": "^0.15.0",
"typescript": "^3.6.4"
},
"dependencies": {
"ethereumjs-util": "^6.1.0",
"ow": "^0.13.2",
"sturdy-websocket": "^0.1.12"
},
"scripts": {
"prepare": "rollup -c",
"build": "npm run prepare",
"test": "echo \"TBD\" && exit 0"
}
}
45 changes: 0 additions & 45 deletions rollup.config.js

This file was deleted.

Loading

0 comments on commit 06ad93e

Please sign in to comment.