Skip to content

Commit 7d423d3

Browse files
authored
Metadata query params for Orders endpoint (#35)
1 parent 225d781 commit 7d423d3

File tree

10 files changed

+80
-10
lines changed

10 files changed

+80
-10
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ on:
88
jobs:
99
build-and-test:
1010
runs-on: ubuntu-latest
11+
1112
strategy:
1213
matrix:
1314
node: ['10', '12', '14', '16']
15+
max-parallel: 1
16+
1417
name: Node ${{ matrix.node }} Test
1518
steps:
1619
- name: Check out code

.mocharc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
require: '@babel/register'
22
recursive: true
3+
timeout: '10000'

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
10.24.1

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.9.0] - 2021-08-17
9+
10+
### Added
11+
12+
- Add support for querying Orders by `metadata`
13+
- Added `transaction_value_eth_gwei` as an alternative way to compute transaction level emissions for ethereum
14+
815
## [1.8.0] - 2021-07-20
916

1017
### Added

package-lock.json

Lines changed: 28 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@patch-technology/patch",
3-
"version": "1.8.0",
3+
"version": "1.9.0",
44
"description": "JavaScript wrapper for the Patch API",
55
"license": "MIT",
66
"repository": {
@@ -21,6 +21,7 @@
2121
"fs": false
2222
},
2323
"dependencies": {
24+
"query-string": "^7.0.1",
2425
"superagent": "^5.3.1"
2526
},
2627
"devDependencies": {
@@ -50,9 +51,6 @@
5051
"mocha": ">=8.1.0",
5152
"prettier": "^2.0.5"
5253
},
53-
"peerDependencies": {
54-
"querystring": "^0.2.0"
55-
},
5654
"files": [
5755
"dist"
5856
],

src/ApiClient.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import superagent from 'superagent';
9-
import querystring from 'querystring';
9+
import querystring from 'query-string';
1010

1111
class ApiClient {
1212
constructor() {
@@ -60,6 +60,9 @@ class ApiClient {
6060
if (param instanceof Date) {
6161
return param.toJSON();
6262
}
63+
if (param instanceof Object) {
64+
return param;
65+
}
6366

6467
return param.toString();
6568
}

src/api/OrdersApi.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,13 @@ export default class OrdersApi {
196196

197197
let pathParams = {};
198198
let queryParams = {
199-
page: opts['page']
199+
page: opts['page'],
200+
201+
metadata: opts['metadata'],
202+
203+
'metadata[example1]': opts['metadataExample1'],
204+
205+
'metadata[example2]': opts['metadataExample2']
200206
};
201207
let headerParams = {};
202208
let formParams = {};

src/model/CreateEthereumEstimateRequest.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ class CreateEthereumEstimateRequest {
2626
obj['gas_used'] = ApiClient.convertToType(data['gas_used'], 'Number');
2727
}
2828

29+
if (data.hasOwnProperty('transaction_value_eth_gwei')) {
30+
obj['transaction_value_eth_gwei'] = ApiClient.convertToType(
31+
data['transaction_value_eth_gwei'],
32+
'Number'
33+
);
34+
}
35+
2936
if (data.hasOwnProperty('project_id')) {
3037
obj['project_id'] = ApiClient.convertToType(
3138
data['project_id'],
@@ -48,6 +55,9 @@ CreateEthereumEstimateRequest.prototype['timestamp'] = undefined;
4855

4956
CreateEthereumEstimateRequest.prototype['gas_used'] = undefined;
5057

58+
CreateEthereumEstimateRequest.prototype['transaction_value_eth_gwei'] =
59+
undefined;
60+
5161
CreateEthereumEstimateRequest.prototype['project_id'] = undefined;
5262

5363
CreateEthereumEstimateRequest.prototype['create_order'] = undefined;

test/integration/orders.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,21 @@ describe('Orders Integration', function () {
4949
const placeOrderResponse = await patch.orders.cancelOrder(orderId);
5050
expect(placeOrderResponse.data.state).to.equal('cancelled');
5151
});
52+
53+
it('supports creating and querying orders by metadata', async function () {
54+
const createOrderResponse = await patch.orders.createOrder({
55+
mass_g: 100,
56+
metadata: { external_id: 'order-123' }
57+
});
58+
59+
const retrieveOrdersResponse = await patch.orders.retrieveOrders({
60+
page: 1,
61+
metadata: { external_id: 'order-' }
62+
});
63+
expect(retrieveOrdersResponse.data.length).to.be.above(0);
64+
65+
retrieveOrdersResponse.data.forEach((order) => {
66+
expect(order.metadata).to.have.all.keys('external_id');
67+
});
68+
});
5269
});

0 commit comments

Comments
 (0)