diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d8b7518..19c8117 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,9 +8,12 @@ on: jobs: build-and-test: runs-on: ubuntu-latest + strategy: matrix: node: ['10', '12', '14', '16'] + max-parallel: 1 + name: Node ${{ matrix.node }} Test steps: - name: Check out code diff --git a/.mocharc.yml b/.mocharc.yml index b9ac7d8..33a0a2e 100644 --- a/.mocharc.yml +++ b/.mocharc.yml @@ -1,2 +1,3 @@ require: '@babel/register' recursive: true +timeout: '10000' diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..dc08cc7 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +10.24.1 diff --git a/CHANGELOG.md b/CHANGELOG.md index a115cb6..489a4d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.9.0] - 2021-08-17 + +### Added + +- Add support for querying Orders by `metadata` +- Added `transaction_value_eth_gwei` as an alternative way to compute transaction level emissions for ethereum + ## [1.8.0] - 2021-07-20 ### Added diff --git a/package-lock.json b/package-lock.json index decad7f..7eda221 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@patch-technology/patch", - "version": "1.8.0", + "version": "1.9.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -2023,9 +2023,7 @@ "decode-uri-component": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/decode-uri-component/-/decode-uri-component-0.2.0.tgz", - "integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=", - "dev": true, - "optional": true + "integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=" }, "dedent": { "version": "0.7.0", @@ -2360,6 +2358,11 @@ } } }, + "filter-obj": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/filter-obj/-/filter-obj-1.1.0.tgz", + "integrity": "sha1-mzERErxsYSehbgFsbF1/GeCAXFs=" + }, "find-cache-dir": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-2.1.0.tgz", @@ -3895,6 +3898,17 @@ "side-channel": "^1.0.4" } }, + "query-string": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/query-string/-/query-string-7.0.1.tgz", + "integrity": "sha512-uIw3iRvHnk9to1blJCG3BTc+Ro56CBowJXKmNNAm3RulvPBzWLRqKSiiDk+IplJhsydwtuNMHi8UGQFcCLVfkA==", + "requires": { + "decode-uri-component": "^0.2.0", + "filter-obj": "^1.1.0", + "split-on-first": "^1.0.0", + "strict-uri-encode": "^2.0.0" + } + }, "randombytes": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", @@ -4446,6 +4460,11 @@ "dev": true, "optional": true }, + "split-on-first": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/split-on-first/-/split-on-first-1.1.0.tgz", + "integrity": "sha512-43ZssAJaMusuKWL8sKUBQXHWOpq8d6CfN/u1p4gUzfJkM05C8rxTmYrkIPTXapZpORA6LkkzcUulJ8FqA7Uudw==" + }, "split-string": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/split-string/-/split-string-3.1.0.tgz", @@ -4479,6 +4498,11 @@ } } }, + "strict-uri-encode": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/strict-uri-encode/-/strict-uri-encode-2.0.0.tgz", + "integrity": "sha1-ucczDHBChi9rFC3CdLvMWGbONUY=" + }, "string-argv": { "version": "0.3.1", "resolved": "https://registry.npmjs.org/string-argv/-/string-argv-0.3.1.tgz", diff --git a/package.json b/package.json index 5c36908..e451d30 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@patch-technology/patch", - "version": "1.8.0", + "version": "1.9.0", "description": "JavaScript wrapper for the Patch API", "license": "MIT", "repository": { @@ -21,6 +21,7 @@ "fs": false }, "dependencies": { + "query-string": "^7.0.1", "superagent": "^5.3.1" }, "devDependencies": { @@ -50,9 +51,6 @@ "mocha": ">=8.1.0", "prettier": "^2.0.5" }, - "peerDependencies": { - "querystring": "^0.2.0" - }, "files": [ "dist" ], diff --git a/src/ApiClient.js b/src/ApiClient.js index f64ccc1..3ae99f1 100644 --- a/src/ApiClient.js +++ b/src/ApiClient.js @@ -6,7 +6,7 @@ */ import superagent from 'superagent'; -import querystring from 'querystring'; +import querystring from 'query-string'; class ApiClient { constructor() { @@ -60,6 +60,9 @@ class ApiClient { if (param instanceof Date) { return param.toJSON(); } + if (param instanceof Object) { + return param; + } return param.toString(); } diff --git a/src/api/OrdersApi.js b/src/api/OrdersApi.js index 710e2c5..9046327 100644 --- a/src/api/OrdersApi.js +++ b/src/api/OrdersApi.js @@ -196,7 +196,13 @@ export default class OrdersApi { let pathParams = {}; let queryParams = { - page: opts['page'] + page: opts['page'], + + metadata: opts['metadata'], + + 'metadata[example1]': opts['metadataExample1'], + + 'metadata[example2]': opts['metadataExample2'] }; let headerParams = {}; let formParams = {}; diff --git a/src/model/CreateEthereumEstimateRequest.js b/src/model/CreateEthereumEstimateRequest.js index 7bc2738..9bdac83 100644 --- a/src/model/CreateEthereumEstimateRequest.js +++ b/src/model/CreateEthereumEstimateRequest.js @@ -26,6 +26,13 @@ class CreateEthereumEstimateRequest { obj['gas_used'] = ApiClient.convertToType(data['gas_used'], 'Number'); } + if (data.hasOwnProperty('transaction_value_eth_gwei')) { + obj['transaction_value_eth_gwei'] = ApiClient.convertToType( + data['transaction_value_eth_gwei'], + 'Number' + ); + } + if (data.hasOwnProperty('project_id')) { obj['project_id'] = ApiClient.convertToType( data['project_id'], @@ -48,6 +55,9 @@ CreateEthereumEstimateRequest.prototype['timestamp'] = undefined; CreateEthereumEstimateRequest.prototype['gas_used'] = undefined; +CreateEthereumEstimateRequest.prototype['transaction_value_eth_gwei'] = + undefined; + CreateEthereumEstimateRequest.prototype['project_id'] = undefined; CreateEthereumEstimateRequest.prototype['create_order'] = undefined; diff --git a/test/integration/orders.test.js b/test/integration/orders.test.js index 9995668..838dac6 100644 --- a/test/integration/orders.test.js +++ b/test/integration/orders.test.js @@ -49,4 +49,21 @@ describe('Orders Integration', function () { const placeOrderResponse = await patch.orders.cancelOrder(orderId); expect(placeOrderResponse.data.state).to.equal('cancelled'); }); + + it('supports creating and querying orders by metadata', async function () { + const createOrderResponse = await patch.orders.createOrder({ + mass_g: 100, + metadata: { external_id: 'order-123' } + }); + + const retrieveOrdersResponse = await patch.orders.retrieveOrders({ + page: 1, + metadata: { external_id: 'order-' } + }); + expect(retrieveOrdersResponse.data.length).to.be.above(0); + + retrieveOrdersResponse.data.forEach((order) => { + expect(order.metadata).to.have.all.keys('external_id'); + }); + }); });