Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@0xproject/connect

Package Overview
Dependencies
Maintainers
5
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@0xproject/connect - npm Package Compare versions

Comparing version 0.4.1 to 0.5.0

8

CHANGELOG.md
# CHANGELOG
## v0.4.0 - _January 11, 2017_
## v0.5.0 - _January 17, 2018_
* Sanitize api endpoint url and remove trailing slashes (#318)
* Improve error message text in HttpClient (#318)
* Stop appending '/v0' to api endpoint url in HttpClient (#318)
## v0.4.0 - _January 11, 2018_
* Prevent getFeesAsync method on HttpClient from mutating input (#296)

@@ -6,0 +12,0 @@

14

lib/src/http_client.js

@@ -46,2 +46,3 @@ "use strict";

var relayer_response_json_parsers_1 = require("./utils/relayer_response_json_parsers");
var TRAILING_SLASHES_REGEX = /\/+$/;
/**

@@ -59,3 +60,3 @@ * This class includes all the functionality related to interacting with a set of HTTP endpoints

assert_1.assert.isHttpUrl('url', url);
this._apiEndpointUrl = url;
this._apiEndpointUrl = url.replace(TRAILING_SLASHES_REGEX, ''); // remove trailing slashes
}

@@ -208,3 +209,3 @@ /**

return __awaiter(this, void 0, void 0, function () {
var params, payload, query, stringifiedParams, url, headers, response, json;
var params, payload, query, stringifiedParams, url, headers, response, json, errorString;
return __generator(this, function (_a) {

@@ -220,3 +221,3 @@ switch (_a.label) {

}
url = this._apiEndpointUrl + "/v0" + path + query;
url = "" + this._apiEndpointUrl + path + query;
headers = new Headers({

@@ -232,8 +233,9 @@ 'content-type': 'application/json',

response = _a.sent();
if (!response.ok) {
throw Error(response.statusText);
}
return [4 /*yield*/, response.json()];
case 2:
json = _a.sent();
if (!response.ok) {
errorString = response.status + " - " + response.statusText + "\n" + requestType + " " + url + "\n" + JSON.stringify(json);
throw Error(errorString);
}
return [2 /*return*/, json];

@@ -240,0 +242,0 @@ }

@@ -66,4 +66,17 @@ "use strict";

});
describe('#constructor', function () {
it('should remove trailing slashes from api url', function () { return __awaiter(_this, void 0, void 0, function () {
var urlWithTrailingSlash, urlWithoutTrailingSlash, client, sanitizedUrl;
return __generator(this, function (_a) {
urlWithTrailingSlash = 'https://slash.com/';
urlWithoutTrailingSlash = 'https://slash.com';
client = new index_1.HttpClient(urlWithTrailingSlash);
sanitizedUrl = client._apiEndpointUrl;
expect(sanitizedUrl).to.be.deep.equal(urlWithoutTrailingSlash);
return [2 /*return*/];
});
}); });
});
describe('#getTokenPairsAsync', function () {
var url = relayUrl + "/v0/token_pairs";
var url = relayUrl + "/token_pairs";
it('gets token pairs', function () { return __awaiter(_this, void 0, void 0, function () {

@@ -83,3 +96,3 @@ var tokenPairs;

}); });
it('gets specfic token pairs for request', function () { return __awaiter(_this, void 0, void 0, function () {
it('gets specific token pairs for request', function () { return __awaiter(_this, void 0, void 0, function () {
var tokenAddress, tokenPairsRequest, urlWithQuery, tokenPairs;

@@ -112,3 +125,3 @@ return __generator(this, function (_a) {

describe('#getOrdersAsync', function () {
var url = relayUrl + "/v0/orders";
var url = relayUrl + "/orders";
it('gets orders', function () { return __awaiter(_this, void 0, void 0, function () {

@@ -157,3 +170,3 @@ var orders;

var orderHash = '0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f';
var url = relayUrl + "/v0/order/" + orderHash;
var url = relayUrl + "/order/" + orderHash;
it('gets order', function () { return __awaiter(_this, void 0, void 0, function () {

@@ -186,3 +199,3 @@ var order;

};
var url = relayUrl + "/v0/orderbook?baseTokenAddress=" + request.baseTokenAddress + "&quoteTokenAddress=" + request.quoteTokenAddress;
var url = relayUrl + "/orderbook?baseTokenAddress=" + request.baseTokenAddress + "&quoteTokenAddress=" + request.quoteTokenAddress;
it('gets order book', function () { return __awaiter(_this, void 0, void 0, function () {

@@ -222,3 +235,3 @@ var orderbook;

};
var url = relayUrl + "/v0/fees";
var url = relayUrl + "/fees";
it('gets fees', function () { return __awaiter(_this, void 0, void 0, function () {

@@ -225,0 +238,0 @@ var fees;

{
"name": "@0xproject/connect",
"version": "0.4.1",
"version": "0.5.0",
"description": "A javascript library for interacting with the standard relayer api",

@@ -39,5 +39,5 @@ "keywords": [

"dependencies": {
"@0xproject/assert": "^0.0.10",
"@0xproject/json-schemas": "^0.7.2",
"@0xproject/utils": "^0.1.3",
"@0xproject/assert": "^0.0.11",
"@0xproject/json-schemas": "^0.7.3",
"@0xproject/utils": "^0.2.0",
"isomorphic-fetch": "^2.2.1",

@@ -49,3 +49,3 @@ "lodash": "^4.17.4",

"devDependencies": {
"@0xproject/tslint-config": "^0.4.1",
"@0xproject/tslint-config": "^0.4.2",
"@types/fetch-mock": "^5.12.1",

@@ -58,4 +58,4 @@ "@types/lodash": "^4.14.86",

"chai-as-promised": "^7.1.0",
"chai-as-promised-typescript-typings": "^0.0.3",
"chai-typescript-typings": "^0.0.1",
"chai-as-promised-typescript-typings": "^0.0.4",
"chai-typescript-typings": "^0.0.2",
"copyfiles": "^1.2.0",

@@ -70,4 +70,4 @@ "dirty-chai": "^2.0.1",

"typescript": "~2.6.1",
"web3-typescript-typings": "^0.9.3"
"web3-typescript-typings": "^0.9.4"
}
}

@@ -11,8 +11,9 @@ const execAsync = require('async-child-process').execAsync;

let version;
postpublish_utils.getLatestTagAndVersionAsync(subPackageName)
postpublish_utils
.getLatestTagAndVersionAsync(subPackageName)
.then(function(result) {
tag = result.tag;
version = result.version;
const releaseName = postpublish_utils.getReleaseName(subPackageName, version);
return postpublish_utils.publishReleaseNotes(tag, releaseName);
const releaseName = postpublish_utils.getReleaseName(subPackageName, version);
return postpublish_utils.publishReleaseNotes(tag, releaseName);
})

@@ -22,8 +23,5 @@ .then(function(release) {

const jsonFilePath = __dirname + '/../' + postpublish_utils.generatedDocsDirectoryName + '/index.json';
return execAsync(
'JSON_FILE_PATH=' + jsonFilePath + ' PROJECT_DIR=' + __dirname + '/.. yarn docs:json',
{
cwd,
}
);
return execAsync('JSON_FILE_PATH=' + jsonFilePath + ' PROJECT_DIR=' + __dirname + '/.. yarn docs:json', {
cwd,
});
})

@@ -40,4 +38,5 @@ .then(function(result) {

});
}).catch (function(err) {
})
.catch(function(err) {
throw err;
});

@@ -23,2 +23,3 @@ import { assert } from '@0xproject/assert';

const TRAILING_SLASHES_REGEX = /\/+$/;
/**

@@ -37,3 +38,3 @@ * This class includes all the functionality related to interacting with a set of HTTP endpoints

assert.isHttpUrl('url', url);
this._apiEndpointUrl = url;
this._apiEndpointUrl = url.replace(TRAILING_SLASHES_REGEX, ''); // remove trailing slashes
}

@@ -135,7 +136,6 @@ /**

}
const url = `${this._apiEndpointUrl}/v0${path}${query}`;
const url = `${this._apiEndpointUrl}${path}${query}`;
const headers = new Headers({
'content-type': 'application/json',
});
const response = await fetch(url, {

@@ -146,8 +146,11 @@ method: requestType,

});
const json = await response.json();
if (!response.ok) {
throw Error(response.statusText);
const errorString = `${response.status} - ${response.statusText}\n${requestType} ${url}\n${JSON.stringify(
json,
)}`;
throw Error(errorString);
}
const json = await response.json();
return json;
}
}

@@ -32,4 +32,13 @@ import { BigNumber } from '@0xproject/utils';

});
describe('#constructor', () => {
it('should remove trailing slashes from api url', async () => {
const urlWithTrailingSlash = 'https://slash.com/';
const urlWithoutTrailingSlash = 'https://slash.com';
const client = new HttpClient(urlWithTrailingSlash);
const sanitizedUrl = (client as any)._apiEndpointUrl;
expect(sanitizedUrl).to.be.deep.equal(urlWithoutTrailingSlash);
});
});
describe('#getTokenPairsAsync', () => {
const url = `${relayUrl}/v0/token_pairs`;
const url = `${relayUrl}/token_pairs`;
it('gets token pairs', async () => {

@@ -40,3 +49,3 @@ fetchMock.get(url, tokenPairsResponseJSON);

});
it('gets specfic token pairs for request', async () => {
it('gets specific token pairs for request', async () => {
const tokenAddress = '0x323b5d4c32345ced77393b3530b1eed0f346429d';

@@ -57,3 +66,3 @@ const tokenPairsRequest = {

describe('#getOrdersAsync', () => {
const url = `${relayUrl}/v0/orders`;
const url = `${relayUrl}/orders`;
it('gets orders', async () => {

@@ -81,3 +90,3 @@ fetchMock.get(url, ordersResponseJSON);

const orderHash = '0xabc67323774bdbd24d94f977fa9ac94a50f016026fd13f42990861238897721f';
const url = `${relayUrl}/v0/order/${orderHash}`;
const url = `${relayUrl}/order/${orderHash}`;
it('gets order', async () => {

@@ -98,3 +107,3 @@ fetchMock.get(url, orderResponseJSON);

};
const url = `${relayUrl}/v0/orderbook?baseTokenAddress=${request.baseTokenAddress}&quoteTokenAddress=${
const url = `${relayUrl}/orderbook?baseTokenAddress=${request.baseTokenAddress}&quoteTokenAddress=${
request.quoteTokenAddress

@@ -124,3 +133,3 @@ }`;

};
const url = `${relayUrl}/v0/fees`;
const url = `${relayUrl}/fees`;
it('gets fees', async () => {

@@ -127,0 +136,0 @@ fetchMock.post(url, feesResponseJSON);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc