From 1f95bec2be45629d7b9a227a28809c64370b3384 Mon Sep 17 00:00:00 2001 From: getlarge Date: Tue, 15 Feb 2022 08:04:36 +0100 Subject: [PATCH 01/14] chore: update dev dependencies --- package.json | 57 ++++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/package.json b/package.json index 488ec09..336a726 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "sideEffects": false, "scripts": { "lint": "eslint .", + "lint:fix": "eslint . --fix", "build": "npm run clean && npm run build:cjs && npm run build:dist", "build:bundle": "webpack", "build:cjs": "cross-env BABEL_ENV=cjs babel ./src -d dist/node", @@ -36,46 +37,44 @@ "doc": "documentation build src/index.js -f md -o API.md -g --markdown-toc" }, "devDependencies": { - "@ava/babel": "^1.0.1", - "@babel/cli": "^7.13.0", - "@babel/core": "^7.13.8", - "@babel/eslint-parser": "^7.13.8", - "@babel/plugin-proposal-export-default-from": "^7.12.13", - "@babel/plugin-proposal-object-rest-spread": "^7.13.8", + "@ava/babel": "^2.0.0", + "@babel/cli": "^7.17.0", + "@babel/core": "^7.17.2", + "@babel/eslint-parser": "^7.17.0", + "@babel/plugin-proposal-export-default-from": "^7.16.7", + "@babel/plugin-proposal-object-rest-spread": "^7.16.7", "@babel/plugin-syntax-async-generators": "^7.8.4", - "@babel/plugin-transform-async-to-generator": "^7.13.0", - "@babel/plugin-transform-object-assign": "^7.12.13", - "@babel/plugin-transform-regenerator": "^7.12.13", - "@babel/plugin-transform-runtime": "^7.13.9", - "@babel/preset-env": "^7.13.9", - "@babel/register": "^7.13.8", + "@babel/plugin-transform-async-to-generator": "^7.16.8", + "@babel/plugin-transform-object-assign": "^7.16.7", + "@babel/plugin-transform-regenerator": "^7.16.7", + "@babel/plugin-transform-runtime": "^7.17.0", + "@babel/preset-env": "^7.16.11", + "@babel/register": "^7.17.0", "ava": "^3.15.0", "babel-loader": "^8.2.2", + "buffer": "^6.0.3", "codecov": "^3.8.1", "cross-env": "^7.0.3", - "documentation": "^13.1.1", - "eslint": "^7.21.0", - "eslint-config-airbnb-base": "^14.2.1", - "eslint-plugin-import": "^2.22.1", - "husky": "^5.1.3", - "lint-staged": "^10.5.4", + "documentation": "^13.2.5", + "eslint": "^8.9.0", + "eslint-config-airbnb-base": "^15.0.0", + "eslint-plugin-import": "^2.25.4", + "husky": "^7.0.4", + "lint-staged": "^12.3.4", "nyc": "^15.1.0", - "release-it": "^14.4.1", - "rewire": "^4.0.1", + "release-it": "^14.12.4", + "rewire": "^6.0.0", "rimraf": "^3.0.2", - "sinon": "^7.3.2", - "terser-webpack-plugin": "^4.2.3", - "webpack": "^4.46.0", - "webpack-cli": "^4.5.0", - "webpack-concat-plugin": "^3.0.0", - "webpack-merge": "^5.7.3", - "webpack-sources": "^2.2.0" + "sinon": "^13.0.1", + "terser-webpack-plugin": "^5.3.1", + "webpack": "^5.68.0", + "webpack-cli": "^4.9.2", + "webpack-merge": "^5.8.0", + "webpack-sources": "^3.2.3" }, "dependencies": { "@babel/runtime-corejs3": "^7.13.9", - "browser-resolve": "^1.11.3", "bs58": "^4.0.1", - "buffer": "^6.0.3", "clone": "^2.1.2", "core-js": "^3.9.1", "crypto-conditions": "2.1.2", From 34289b064047ff2d21385a32ec9a238b90b91696 Mon Sep 17 00:00:00 2001 From: getlarge Date: Tue, 15 Feb 2022 08:06:05 +0100 Subject: [PATCH 02/14] chore: update wepback config declare Buffer as webpack plugin --- src/transaction.js | 1 - webpack.common.js | 13 +++++++++++-- webpack.config.js | 4 ++-- webpack.development.js | 2 -- webpack.parts.js | 4 ++-- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/transaction.js b/src/transaction.js index 3b33213..2142ad0 100644 --- a/src/transaction.js +++ b/src/transaction.js @@ -2,7 +2,6 @@ // SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0) // Code is Apache-2.0 and docs are CC-BY-4.0 -import { Buffer } from 'buffer' import stableStringify from 'json-stable-stringify' import clone from 'clone' import base58 from 'bs58' diff --git a/webpack.common.js b/webpack.common.js index a7194e1..c9dec12 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -6,7 +6,8 @@ 'use strict' -const { paths } = require('./webpack.parts.js') +const { ProvidePlugin } = require('webpack') +const { paths } = require('./webpack.parts') module.exports = { entry: paths.entry, @@ -24,10 +25,18 @@ module.exports = { }, optimization: { minimize: true, - noEmitOnErrors: true + emitOnErrors: false }, resolve: { extensions: ['.js'], modules: ['node_modules'], + fallback: { + buffer: require.resolve('buffer/'), + } }, + plugins: [ + new ProvidePlugin({ + Buffer: ['buffer', 'Buffer'] + }) + ] } diff --git a/webpack.config.js b/webpack.config.js index 8136429..cbf731f 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -8,9 +8,9 @@ const PRODUCTION = process.env.NODE_ENV === 'production' -const common = require('./webpack.common.js') +const common = require('./webpack.common') -const { outputs } = require('./webpack.parts.js') +const { outputs } = require('./webpack.parts') // '[libraryTarget]': [file extension] const OUTPUT_MAPPING = { diff --git a/webpack.development.js b/webpack.development.js index e4249a6..7136244 100644 --- a/webpack.development.js +++ b/webpack.development.js @@ -14,11 +14,9 @@ module.exports = { minimizer: [ new TerserPlugin({ test: /vendor/, - sourceMap: false }), new TerserPlugin({ test: /^((?!(vendor)).)*.js$/, - sourceMap: false }) ], splitChunks: { diff --git a/webpack.parts.js b/webpack.parts.js index eb292d8..8a3e2d7 100644 --- a/webpack.parts.js +++ b/webpack.parts.js @@ -9,8 +9,8 @@ const path = require('path') const { merge } = require('webpack-merge') -const development = require('./webpack.development.js') -const production = require('./webpack.production.js') +const development = require('./webpack.development') +const production = require('./webpack.production') const AddVendorsPlugin = require('./plugins/add-vendors-plugin') From 38819a5934b16e88c8d58e516e03ac4a1f5508a9 Mon Sep 17 00:00:00 2001 From: getlarge Date: Tue, 15 Feb 2022 08:06:31 +0100 Subject: [PATCH 03/14] fix: improve promises handling --- src/request.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/request.js b/src/request.js index 8ccaa40..7bdd67c 100644 --- a/src/request.js +++ b/src/request.js @@ -70,7 +70,7 @@ export default class Request { const requestTimeout = timeout ? timeout - backoffTimedelta : timeout return baseRequest(apiUrl, requestConfig, requestTimeout) - .then(async (res) => { + .then((res) => { this.connectionError = null return res.json() }) @@ -111,6 +111,8 @@ export default class Request { } static sleep(ms) { - return new Promise(resolve => setTimeout(resolve, ms)) + return new Promise(resolve => { + setTimeout(resolve, ms) + }) } } From dc353ee5bc5ce0175eb53778c3e96058f750dc9e Mon Sep 17 00:00:00 2001 From: getlarge Date: Tue, 15 Feb 2022 08:07:38 +0100 Subject: [PATCH 04/14] chore: update lint rules --- .eslintrc.js | 2 +- test/transaction/test_cryptoconditions.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 7e11df5..a5b8972 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -193,7 +193,7 @@ module.exports = { ], }, ], - + 'import/no-extraneous-dependencies': ['error', { 'devDependencies': true }], /** * ES6-specific Issues * (http://eslint.org/docs/rules/#ecmascript-6) diff --git a/test/transaction/test_cryptoconditions.js b/test/transaction/test_cryptoconditions.js index d5741ce..ffcc86b 100644 --- a/test/transaction/test_cryptoconditions.js +++ b/test/transaction/test_cryptoconditions.js @@ -92,7 +92,8 @@ test('Fulfillment correctly formed', t => { const msgHash = sha256Hash(msgUniqueFulfillment) t.truthy(validateFulfillment( - txSigned.inputs[0].fulfillment, txCreate.outputs[0].condition.uri, + txSigned.inputs[0].fulfillment, + txCreate.outputs[0].condition.uri, Buffer.from(msgHash, 'hex') )) }) From c5fe1346b9a197a4baf26ef35a1adb82745bc371 Mon Sep 17 00:00:00 2001 From: getlarge Date: Tue, 15 Feb 2022 14:06:19 +0100 Subject: [PATCH 05/14] chore: update dependencies --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 336a726..0b0b015 100644 --- a/package.json +++ b/package.json @@ -73,17 +73,17 @@ "webpack-sources": "^3.2.3" }, "dependencies": { - "@babel/runtime-corejs3": "^7.13.9", + "@babel/runtime-corejs3": "^7.17.2", "bs58": "^4.0.1", "clone": "^2.1.2", - "core-js": "^3.9.1", - "crypto-conditions": "2.1.2", + "core-js": "^3.21.0", + "crypto-conditions": "2.2.1", "decamelize": "^5.0.0", "es6-promise": "^4.2.8", "fetch-ponyfill": "^7.1.0", "js-sha3": "^0.8.0", "json-stable-stringify": "^1.0.1", - "query-string": "^6.14.1", + "query-string": "^7.1.1", "sprintf-js": "^1.1.2", "tweetnacl": "^1.0.3" }, From 8c0c72622db5375a5fbdbd608fb257a351c170fc Mon Sep 17 00:00:00 2001 From: getlarge Date: Tue, 15 Feb 2022 14:10:49 +0100 Subject: [PATCH 06/14] feat: ensure timeout and request are properly cleared --- src/baseRequest.js | 57 +++++++++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 18 deletions(-) diff --git a/src/baseRequest.js b/src/baseRequest.js index 8f52478..a2f9c86 100644 --- a/src/baseRequest.js +++ b/src/baseRequest.js @@ -9,14 +9,14 @@ import { vsprintf } from 'sprintf-js' import formatText from './format_text' import stringifyAsQueryParam from './stringify_as_query_param' -const fetch = fetchPonyfill(Promise) +const fetch = fetchPonyfill({ Promise }) export function ResponseError(message, status, requestURI) { this.name = 'ResponseError' this.message = message this.status = status this.requestURI = requestURI - this.stack = (new Error()).stack + this.stack = new Error().stack } ResponseError.prototype = new Error() @@ -26,17 +26,27 @@ ResponseError.prototype = new Error() * Timeout function following https://github.com/github/fetch/issues/175#issuecomment-284787564 * @param {integer} obj Source object * @param {Promise} filter Array of key names to select or function to invoke per iteration + * @param {AbortController} controller AbortController instance bound to fetch * @return {Object} TimeoutError if the time was consumed, otherwise the Promise will be resolved */ -function timeout(ms, promise) { +function timeout(ms, promise, controller) { return new Promise((resolve, reject) => { - setTimeout(() => { + const nodeTimeout = setTimeout(() => { + controller.abort() const errorObject = { - message: 'TimeoutError' + message: 'TimeoutError', } reject(new Error(errorObject)) }, ms) - promise.then(resolve, reject) + promise + .then((res) => { + clearTimeout(nodeTimeout) + resolve(res) + }) + .catch((err) => { + clearTimeout(nodeTimeout) + reject(err) + }) }) } @@ -88,25 +98,30 @@ function handleResponse(res) { * @return {Promise} If requestTimeout the timeout function will be called. Otherwise resolve the * Promise with the handleResponse function */ -export default function baseRequest(url, { - jsonBody, - query, - urlTemplateSpec, - ...fetchConfig -} = {}, requestTimeout) { +export default function baseRequest( + url, + { + jsonBody, query, urlTemplateSpec, ...fetchConfig + } = {}, + requestTimeout = 0 +) { let expandedUrl = url if (urlTemplateSpec != null) { if (Array.isArray(urlTemplateSpec) && urlTemplateSpec.length) { // Use vsprintf for the array call signature expandedUrl = vsprintf(url, urlTemplateSpec) - } else if (urlTemplateSpec && + } else if ( + urlTemplateSpec && typeof urlTemplateSpec === 'object' && - Object.keys(urlTemplateSpec).length) { + Object.keys(urlTemplateSpec).length + ) { expandedUrl = formatText(url, urlTemplateSpec) } else if (process.env.NODE_ENV !== 'production') { // eslint-disable-next-line no-console - console.warn('Supplied urlTemplateSpec was not an array or object. Ignoring...') + console.warn( + 'Supplied urlTemplateSpec was not an array or object. Ignoring...' + ) } } @@ -124,11 +139,17 @@ export default function baseRequest(url, { if (jsonBody != null) { fetchConfig.body = JSON.stringify(jsonBody) } + if (requestTimeout) { - return timeout(requestTimeout, fetch.fetch(expandedUrl, fetchConfig)) + const controller = new AbortController() + const { signal } = controller + return timeout( + requestTimeout, + fetch.fetch(expandedUrl, { ...fetchConfig, signal }), + controller + ) .then(handleResponse) } else { - return fetch.fetch(expandedUrl, fetchConfig) - .then(handleResponse) + return fetch.fetch(expandedUrl, fetchConfig).then(handleResponse) } } From 46599f5446857b916038a6e2105ece0c687b9171 Mon Sep 17 00:00:00 2001 From: getlarge Date: Tue, 15 Feb 2022 14:11:30 +0100 Subject: [PATCH 07/14] feat: add `limit` query for transaction search requests --- src/connection.js | 10 ++++++---- test/connection/test_connection.js | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/connection.js b/src/connection.js index 94ac3cc..93cd010 100644 --- a/src/connection.js +++ b/src/connection.js @@ -178,10 +178,11 @@ export default class Connection { /** * @param search */ - searchAssets(search) { + searchAssets(search, limit = 10) { return this._req(Connection.getApiUrls('assets'), { query: { - search + search, + limit } }) } @@ -189,10 +190,11 @@ export default class Connection { /** * @param search */ - searchMetadata(search) { + searchMetadata(search, limit = 10) { return this._req(Connection.getApiUrls('metadata'), { query: { - search + search, + limit } }) } diff --git a/test/connection/test_connection.js b/test/connection/test_connection.js index 3efd3c1..16b273f 100644 --- a/test/connection/test_connection.js +++ b/test/connection/test_connection.js @@ -225,7 +225,7 @@ test('Get asset for text', t => { conn.searchAssets(search) t.truthy(conn._req.calledWith( expectedPath, - { query: { search } } + { query: { search, limit: 10 } } )) }) @@ -239,6 +239,6 @@ test('Get metadata for text', t => { conn.searchMetadata(search) t.truthy(conn._req.calledWith( expectedPath, - { query: { search } } + { query: { search, limit: 10 } } )) }) From fbc3d79d98b1326a3dd2a5df0e12c9b961a1fdbc Mon Sep 17 00:00:00 2001 From: getlarge Date: Tue, 15 Feb 2022 14:12:27 +0100 Subject: [PATCH 08/14] feat: update connection typedefs --- types/connection.d.ts | 36 +++++++++++++++++++++++++++--------- types/sanitize.d.ts | 6 +++--- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/types/connection.d.ts b/types/connection.d.ts index 9dccd0c..75b3771 100644 --- a/types/connection.d.ts +++ b/types/connection.d.ts @@ -19,6 +19,16 @@ export interface InputNode { endpoint: string; } +export type AssetResult = { + id: string; + data: Record; +}; + +export type MetadataResult = { + id: string; + metadata: Record; +}; + export enum Endpoints { blocks = 'blocks', blocksDetail = 'blocksDetail', @@ -76,8 +86,8 @@ export interface EndpointsResponse< [Endpoints.transactionsDetail]: O extends TransactionOperations.CREATE ? CreateTransaction : TransferTransaction; - [Endpoints.assets]: { id: string; data: Record }[]; - [Endpoints.metadata]: { id: string; metadata: Record }[]; + [Endpoints.assets]: AssetResult[]; + [Endpoints.metadata]: MetadataResult[]; } export default class Connection { @@ -111,7 +121,9 @@ export default class Connection { transactionId: string ): Promise[Endpoints.transactionsDetail]>; - listBlocks(transactionId: string): Promise; + listBlocks( + transactionId: string + ): Promise; listOutputs( publicKey: string, @@ -124,7 +136,7 @@ export default class Connection { ): Promise[Endpoints.transactions]>; postTransaction< - O = TransactionOperations.CREATE, + O extends TransactionOperations = TransactionOperations.CREATE, A = Record, M = Record >( @@ -132,7 +144,7 @@ export default class Connection { ): Promise[Endpoints.transactionsCommit]>; postTransactionSync< - O = TransactionOperations.CREATE, + O extends TransactionOperations = TransactionOperations.CREATE, A = Record, M = Record >( @@ -140,7 +152,7 @@ export default class Connection { ): Promise[Endpoints.transactionsSync]>; postTransactionAsync< - O = TransactionOperations.CREATE, + O extends TransactionOperations = TransactionOperations.CREATE, A = Record, M = Record >( @@ -148,14 +160,20 @@ export default class Connection { ): Promise[Endpoints.transactionsAsync]>; postTransactionCommit< - O = TransactionOperations.CREATE, + O extends TransactionOperations = TransactionOperations.CREATE, A = Record, M = Record >( transaction: TransactionCommon ): Promise[Endpoints.transactionsCommit]>; - searchAssets(search: string): Promise; + searchAssets( + search: string, + limit?: number + ): Promise; - searchMetadata(search: string): Promise; + searchMetadata( + search: string, + limit?: number + ): Promise; } diff --git a/types/sanitize.d.ts b/types/sanitize.d.ts index 48ab058..61e29ef 100644 --- a/types/sanitize.d.ts +++ b/types/sanitize.d.ts @@ -6,8 +6,8 @@ declare type FilterFn = (val: any, key?: string) => void; declare function filterFromObject>( obj: I, - filter: Array | FilterFn, - conf: { isInclusion?: boolean } = {} + filter: Array | FilterFn, + conf: { isInclusion?: boolean } ): Partial; declare function applyFilterOnObject>( @@ -17,7 +17,7 @@ declare function applyFilterOnObject>( declare function selectFromObject>( obj: I, - filter: Array | FilterFn + filter: Array | FilterFn ): Partial; export default function sanitize>( From 1ba488b28f6d99fff68405669325a3824bd5f969 Mon Sep 17 00:00:00 2001 From: getlarge Date: Tue, 15 Feb 2022 14:13:04 +0100 Subject: [PATCH 09/14] fix: improve transaction typedefs --- types/transaction.d.ts | 50 +++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/types/transaction.d.ts b/types/transaction.d.ts index 7d1c9bc..0984678 100644 --- a/types/transaction.d.ts +++ b/types/transaction.d.ts @@ -33,9 +33,9 @@ export enum TransactionOperations { } export interface TransactionCommon< - O = TransactionOperations, - A = Record, - M = Record + O extends TransactionOperations = TransactionOperations.CREATE, + A extends Record = Record, + M extends Record = Record > { id?: string; inputs: TransactionInput[]; @@ -47,16 +47,16 @@ export interface TransactionCommon< } export interface TransactionCommonSigned< - O = TransactionOperations, - A = Record, - M = Record + O extends TransactionOperations = TransactionOperations.CREATE, + A extends Record = Record, + M extends Record = Record > extends Omit, 'id'> { id: string; } export type TransactionAssetMap< Operation, - A = Record + A extends Record > = Operation extends TransactionOperations.CREATE ? { data: A; @@ -66,18 +66,19 @@ export type TransactionAssetMap< }; export interface CreateTransaction< - A = Record, - M = Record + A extends Record = Record, + M extends Record = Record > extends TransactionCommon { id: string; asset: TransactionAssetMap; operation: TransactionOperations.CREATE; } -export interface TransferTransaction> - extends TransactionCommon { +export interface TransferTransaction< + M extends Record = Record +> extends TransactionCommon { id: string; - asset: TransactionAssetMap; + asset: TransactionAssetMap; operation: TransactionOperations.TRANSFER; } @@ -96,22 +97,22 @@ interface TxTemplate { version: '2.0'; } -declare type DelegateSignFunction = ( +export type DelegateSignFunction = ( serializedTransaction: string, input: TransactionInput, index?: number ) => string; -declare type DelegateSignFunctionAsync = ( +export type DelegateSignFunctionAsync = ( serializedTransaction: string, input: TransactionInput, index?: number ) => Promise; export default class Transaction { - static serializeTransactionIntoCanonicalString( - transaction: TransactionCommon - ): string; + static serializeTransactionIntoCanonicalString< + O extends TransactionOperations = TransactionOperations + >(transaction: TransactionCommon): string; static serializeTransactionIntoCanonicalString( transaction: CreateTransaction | TransferTransaction @@ -185,7 +186,7 @@ export default class Transaction { static makeTransactionTemplate(): TxTemplate; static makeTransaction< - O extends keyof TransactionOperations, + O extends TransactionOperations, A = Record, M = Record >( @@ -212,18 +213,23 @@ export default class Transaction { metadata: M ): TransferTransaction; - static signTransaction( + static signTransaction< + O extends TransactionOperations = TransactionOperations.CREATE + >( transaction: TransactionCommon, ...privateKeys: string[] ): TransactionCommonSigned; - - static delegateSignTransaction( + static delegateSignTransaction< + O extends TransactionOperations = TransactionOperations.CREATE + >( transaction: TransactionCommon, signFn: DelegateSignFunction ): TransactionCommonSigned; - static delegateSignTransactionAsync( + static delegateSignTransactionAsync< + O extends TransactionOperations = TransactionOperations.CREATE + >( transaction: TransactionCommon, signFn: DelegateSignFunctionAsync ): Promise>; From 30c15b962b0497a03b249a42588fa7565944a754 Mon Sep 17 00:00:00 2001 From: getlarge Date: Tue, 15 Feb 2022 14:13:13 +0100 Subject: [PATCH 10/14] feat: export extra types --- types/index.d.ts | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index a10316a..c590991 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -2,10 +2,38 @@ // SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0) // Code is Apache-2.0 and docs are CC-BY-4.0 -import Ed25519Keypair from './Ed25519Keypair' -import Connection from './connection' -import Transaction from './transaction' -import ccJsonLoad from './utils/ccJsonLoad' -import ccJsonify from './utils/ccJsonify' +import Ed25519Keypair from './Ed25519Keypair'; +import Connection, { + Endpoints, + EndpointsResponse, + EndpointsUrl, +} from './connection'; +import Transaction, { + CreateTransaction, + TransactionCommon, + TransactionCommonSigned, + TransactionInput, + TransactionOutput, + TransferTransaction, + TransactionUnspentOutput, + TransactionOperations, +} from './transaction'; +import ccJsonLoad from './utils/ccJsonLoad'; +import ccJsonify from './utils/ccJsonify'; -export { ccJsonLoad, ccJsonify, Connection, Ed25519Keypair, Transaction } +export { ccJsonLoad, ccJsonify, Connection, Ed25519Keypair, Transaction }; + +// Extras +export { + Endpoints, + EndpointsResponse, + EndpointsUrl, + CreateTransaction, + TransactionCommon, + TransactionCommonSigned, + TransactionInput, + TransactionOutput, + TransferTransaction, + TransactionUnspentOutput, + TransactionOperations, +}; From ae13da59b44b21d40a4e79902e8ff2082c94cbc0 Mon Sep 17 00:00:00 2001 From: getlarge Date: Wed, 16 Feb 2022 07:38:57 +0100 Subject: [PATCH 11/14] ci: create GH action workflow --- .github/workflows/ci.yaml | 65 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 .github/workflows/ci.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..1884ceb --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,65 @@ +name: 'JS BigChainDB driver CI' + +on: + push: + branches: + - main + paths-ignore: + - README.md + - API.md + - docs/*.rst + pull_request: + branches: + - main + types: + - ready_for_review + - opened + - reopened + - synchronize + paths-ignore: + - README.md + - API.md + - docs/*.rst + +jobs: + test: + runs-on: ubuntu-latest + if: github.event_name == 'release' || github.event_name == 'push' || !github.event.pull_request.draft + timeout-minutes: 10 + + steps: + - name: Checkout the commit + uses: actions/checkout@v2 + + - name: Set up Node + uses: actions/setup-node@v2 + with: + node-version: 14 + + - name: Cache dependencies + id: cache + uses: actions/cache@v2 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + + - name: Install dependencies + env: + HUSKY_SKIP_INSTALL: 'true' + run: npm install + + - name: Lint + run: npm run lint + + - name: Build + run: npm run build + + - name: Build docker + run: | + echo Building and starting up docker containers + docker-compose -f ./docker-compose.yml up + + - name: Test + run: npm run test From 2f3b2dbca16c6cfb84494deef04ebd8b72920ce3 Mon Sep 17 00:00:00 2001 From: getlarge Date: Wed, 16 Feb 2022 08:05:51 +0100 Subject: [PATCH 12/14] ci: run BCDB node in background --- .github/workflows/ci.yaml | 65 --------------------------------------- .github/workflows/ci.yml | 11 ++++--- 2 files changed, 7 insertions(+), 69 deletions(-) delete mode 100644 .github/workflows/ci.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml deleted file mode 100644 index 1884ceb..0000000 --- a/.github/workflows/ci.yaml +++ /dev/null @@ -1,65 +0,0 @@ -name: 'JS BigChainDB driver CI' - -on: - push: - branches: - - main - paths-ignore: - - README.md - - API.md - - docs/*.rst - pull_request: - branches: - - main - types: - - ready_for_review - - opened - - reopened - - synchronize - paths-ignore: - - README.md - - API.md - - docs/*.rst - -jobs: - test: - runs-on: ubuntu-latest - if: github.event_name == 'release' || github.event_name == 'push' || !github.event.pull_request.draft - timeout-minutes: 10 - - steps: - - name: Checkout the commit - uses: actions/checkout@v2 - - - name: Set up Node - uses: actions/setup-node@v2 - with: - node-version: 14 - - - name: Cache dependencies - id: cache - uses: actions/cache@v2 - with: - path: ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-node- - - - name: Install dependencies - env: - HUSKY_SKIP_INSTALL: 'true' - run: npm install - - - name: Lint - run: npm run lint - - - name: Build - run: npm run build - - - name: Build docker - run: | - echo Building and starting up docker containers - docker-compose -f ./docker-compose.yml up - - - name: Test - run: npm run test diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2583ffc..9c08ce9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,6 +45,11 @@ jobs: restore-keys: | ${{ runner.os }}-node- + - name: Run BigChainDB node + run: | + echo Building and starting up docker containers + docker-compose -f ./docker-compose.yml up -d + - name: Install dependencies env: HUSKY_SKIP_INSTALL: 'true' @@ -56,10 +61,8 @@ jobs: - name: Build run: npm run build - - name: Build docker - run: | - echo Building and starting up docker containers - docker-compose -f ./docker-compose.yml up + # ensure BCDB node is up and running + - run: sleep 10 - name: Test run: npm run test From eee8da4b78f750588677331b2680f0f33687883f Mon Sep 17 00:00:00 2001 From: getlarge Date: Wed, 16 Feb 2022 08:17:30 +0100 Subject: [PATCH 13/14] fix: use abort-controller pkg for node <15 --- package.json | 1 + src/baseRequest.js | 2 ++ 2 files changed, 3 insertions(+) diff --git a/package.json b/package.json index 0b0b015..8f3b676 100644 --- a/package.json +++ b/package.json @@ -74,6 +74,7 @@ }, "dependencies": { "@babel/runtime-corejs3": "^7.17.2", + "abort-controller": "^3.0.0", "bs58": "^4.0.1", "clone": "^2.1.2", "core-js": "^3.21.0", diff --git a/src/baseRequest.js b/src/baseRequest.js index a2f9c86..959e339 100644 --- a/src/baseRequest.js +++ b/src/baseRequest.js @@ -2,6 +2,8 @@ // SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0) // Code is Apache-2.0 and docs are CC-BY-4.0 +// TODO: remove abort-controller when using Node >=15 +import AbortController from 'abort-controller' import { Promise } from 'es6-promise' import fetchPonyfill from 'fetch-ponyfill' import { vsprintf } from 'sprintf-js' From 7a12ee7eb9d237b231a71ad75c2c8b5ddb15a16b Mon Sep 17 00:00:00 2001 From: getlarge Date: Wed, 16 Feb 2022 08:17:44 +0100 Subject: [PATCH 14/14] ci: extends wait delay --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9c08ce9..9ae673d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -62,7 +62,7 @@ jobs: run: npm run build # ensure BCDB node is up and running - - run: sleep 10 + - run: sleep 20 - name: Test run: npm run test