Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ on:
jobs:
build-and-test:
runs-on: ubuntu-latest

strategy:
matrix:
node: ['10', '12', '14', '16']
max-parallel: 1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will slow down CI but reduce the amount of "collisions" we may see due to the same tests running on the same endpoints in parallel. Considering we don't run CI on these projects very frequently, I feel the stability is worth the extra 2 minutes until we change up the test suite to not hit the real API


name: Node ${{ matrix.node }} Test
steps:
- name: Check out code
Expand Down
1 change: 1 addition & 0 deletions .mocharc.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
require: '@babel/register'
recursive: true
timeout: '10000'
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10.24.1
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add the new parameter for ETH here too?

- Added `transaction_value_eth_gwei` as an alternative way to compute transaction level emissions for ethereum

## [1.8.0] - 2021-07-20

### Added
Expand Down
32 changes: 28 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -21,6 +21,7 @@
"fs": false
},
"dependencies": {
"query-string": "^7.0.1",
"superagent": "^5.3.1"
},
"devDependencies": {
Expand Down Expand Up @@ -50,9 +51,6 @@
"mocha": ">=8.1.0",
"prettier": "^2.0.5"
},
"peerDependencies": {
"querystring": "^0.2.0"
},
"files": [
"dist"
],
Expand Down
5 changes: 4 additions & 1 deletion src/ApiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import superagent from 'superagent';
import querystring from 'querystring';
import querystring from 'query-string';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are 2 changes in this file that fix support for deep objects. This is the first and it swaps out these two very similar libraries because the original one did not encode the urls correctly

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This answers my other question, thanks!


class ApiClient {
constructor() {
Expand Down Expand Up @@ -60,6 +60,9 @@ class ApiClient {
if (param instanceof Date) {
return param.toJSON();
}
if (param instanceof Object) {
return param;
Comment on lines +63 to +64
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

object query params will be encoded correctly by the library so they must be returned as is. Otherwise toString is called on them and we get "Object"

}

return param.toString();
}
Expand Down
8 changes: 7 additions & 1 deletion src/api/OrdersApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down
10 changes: 10 additions & 0 deletions src/model/CreateEthereumEstimateRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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;
Expand Down
17 changes: 17 additions & 0 deletions test/integration/orders.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});