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

@marketprotocol/mpx-api-client

Package Overview
Dependencies
Maintainers
7
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@marketprotocol/mpx-api-client - npm Package Compare versions

Comparing version 0.14.0 to 1.0.0

84

index.js

@@ -88,9 +88,9 @@ "use strict";

HOST_NOT_SET_ERROR: new Error("host url not set. Invoke the 'setHost()' function with your mpxAPI host")
/**
* MPXAPIError represents an Error that is gotten from the api response.
* It is usually returned as an Array of MPXAPIError.
*
*/
};
/**
* MPXAPIError represents an Error that is gotten from the api response.
* It is usually returned as an Array of MPXAPIError.
*
*/
};
exports.Errors = Errors;

@@ -115,3 +115,3 @@

Object.assign(_assertThisInitialized(_this), (0, _pick.default)(error, ['id', 'status', 'code', 'title', 'detail']));
Object.assign(_assertThisInitialized(_this), (0, _pick.default)(error, ["id", "status", "code", "title", "detail"]));
return _this;

@@ -136,7 +136,7 @@ }

var url = function url(path, filterString, id) {
if (typeof host !== 'string') {
if (typeof host !== "string") {
throw Errors.HOST_NOT_SET_ERROR;
}
var url = host + path + (id !== null ? "/".concat(id) : '') + (filterString !== null ? "".concat('?' + filterString) : '');
var url = host + path + (id !== null ? "/".concat(id) : "") + (filterString !== null ? "".concat("?" + filterString) : "");
return url;

@@ -161,5 +161,5 @@ };

var serializeRequest = function serializeRequest(path, body) {
var JSONAPISerializer = require('jsonapi-serializer').Serializer;
var JSONAPISerializer = require("jsonapi-serializer").Serializer;
var pathSegments = path.split('/').filter(Boolean);
var pathSegments = path.split("/").filter(Boolean);
var type = body.type || (0, _kebabCase.default)(pathSegments[0]);

@@ -172,3 +172,3 @@

var serializedRequest = Object.assign(new JSONAPISerializer(type, {
attributes: (0, _without.default)(Object.keys(body), 'id')
attributes: (0, _without.default)(Object.keys(body), "id")
}).serialize(body));

@@ -200,3 +200,3 @@ return serializedRequest;

return {
'Content-Type': 'application/vnd.api+json',
"Content-Type": "application/vnd.api+json",
Authorization: "Bearer ".concat(authorizationToken)

@@ -206,3 +206,3 @@ };

return {
'Content-Type': 'application/vnd.api+json'
"Content-Type": "application/vnd.api+json"
};

@@ -237,6 +237,6 @@ }

if (deserialize) {
var JSONAPIDeserializer = require('jsonapi-serializer').Deserializer;
var JSONAPIDeserializer = require("jsonapi-serializer").Deserializer;
var opts = {
keyForAttribute: 'camelCase'
keyForAttribute: "camelCase"
};

@@ -266,3 +266,3 @@ return new JSONAPIDeserializer(opts).deserialize(json).then(function (deserializedData) {

*/
Root: '/',
Root: "/",

@@ -273,3 +273,3 @@ /**

*/
Contracts: '/contracts',
Contracts: "/contracts",

@@ -280,3 +280,3 @@ /**

*/
FeeRecipients: '/fee_recipients',
FeeRecipients: "/fee_recipients",

@@ -287,3 +287,3 @@ /**

*/
Fills: '/fills',
Fills: "/fills",

@@ -294,3 +294,3 @@ /**

*/
JWT: '/json_web_tokens',
JWT: "/json_web_tokens",

@@ -301,3 +301,3 @@ /**

*/
Me: '/me',
Me: "/me",

@@ -308,3 +308,3 @@ /**

*/
Notifications: '/notifications',
Notifications: "/notifications",

@@ -315,3 +315,3 @@ /**

*/
OrderBook: '/orderbooks',
OrderBook: "/orderbooks",

@@ -322,3 +322,3 @@ /**

*/
Orders: '/orders',
Orders: "/orders",

@@ -329,9 +329,15 @@ /**

*/
Rates: '/rates',
Rates: "/rates",
/**
* Path to fetch Position Token Events on the API.
*
*/
PositionTokenEvents: "/position_token_events",
/**
* Path to API settings
*
*/
Settings: '/settings',
Settings: "/settings",

@@ -342,3 +348,3 @@ /**

*/
TokenPairs: '/token_pairs',
TokenPairs: "/token_pairs",

@@ -349,3 +355,9 @@ /**

*/
UserSettings: '/user_settings'
UserSettings: "/user_settings",
/**
* Path to fetch User Rewards on the API.
*
*/
UserRewards: "/user_rewards"
};

@@ -394,4 +406,4 @@ /**

setGlobalResponseHandler: function setGlobalResponseHandler(handler) {
if (handler !== null && typeof handler !== 'function') {
throw new Error('global response handler must either be null or a function.');
if (handler !== null && typeof handler !== "function") {
throw new Error("global response handler must either be null or a function.");
}

@@ -423,3 +435,3 @@

return fetch(url(path, filterString, id), {
method: 'GET',
method: "GET",
headers: createHeader(authorizationToken)

@@ -455,3 +467,3 @@ }).then(jsonAPIResponseHandler(deserialize));

return fetch(url(path, filterString, id), {
method: 'POST',
method: "POST",
headers: createHeader(authorizationToken),

@@ -488,3 +500,3 @@ body: jsonAPIRequestHandler(path, body, serializeRequest)

return fetch(url(path, filterString, id), {
method: 'PATCH',
method: "PATCH",
headers: createHeader(authorizationToken),

@@ -521,3 +533,3 @@ body: jsonAPIRequestHandler(path, body, serializeRequest)

return fetch(url(path, filterString, id), {
method: 'PUT',
method: "PUT",
headers: createHeader(authorizationToken),

@@ -549,3 +561,3 @@ body: jsonAPIRequestHandler(path, body, serializeRequest)

return fetch(url(path, filterString, id), {
method: 'DELETE',
method: "DELETE",
headers: createHeader(authorizationToken)

@@ -552,0 +564,0 @@ }).then(jsonAPIResponseHandler(deserialize));

@@ -1,5 +0,5 @@

import without from 'lodash/without';
import kebabCase from 'lodash/kebabCase';
import pick from 'lodash/pick';
import map from 'lodash/map';
import without from "lodash/without";
import kebabCase from "lodash/kebabCase";
import pick from "lodash/pick";
import map from "lodash/map";

@@ -46,3 +46,3 @@ /////// Type Definitions

// prevent promise handlers from erroring
})
});
}

@@ -57,4 +57,6 @@ } catch (err) {

export const Errors = {
HOST_NOT_SET_ERROR: new Error(`host url not set. Invoke the 'setHost()' function with your mpxAPI host`)
}
HOST_NOT_SET_ERROR: new Error(
`host url not set. Invoke the 'setHost()' function with your mpxAPI host`
)
};

@@ -78,3 +80,3 @@ /**

this,
pick(error, ['id', 'status', 'code', 'title', 'detail'])
pick(error, ["id", "status", "code", "title", "detail"])
);

@@ -94,3 +96,3 @@ }

const url = (path, filterString, id) => {
if (typeof host !== 'string') {
if (typeof host !== "string") {
throw Errors.HOST_NOT_SET_ERROR;

@@ -101,4 +103,4 @@ }

path +
(id !== null ? `/${id}` : '') +
(filterString !== null ? `${'?' + filterString}` : '');
(id !== null ? `/${id}` : "") +
(filterString !== null ? `${"?" + filterString}` : "");

@@ -123,4 +125,4 @@ return url;

const serializeRequest = (path, body) => {
const JSONAPISerializer = require('jsonapi-serializer').Serializer;
const pathSegments = path.split('/').filter(Boolean);
const JSONAPISerializer = require("jsonapi-serializer").Serializer;
const pathSegments = path.split("/").filter(Boolean);
const type = body.type || kebabCase(pathSegments[0]);

@@ -134,3 +136,3 @@

new JSONAPISerializer(type, {
attributes: without(Object.keys(body), 'id')
attributes: without(Object.keys(body), "id")
}).serialize(body)

@@ -161,3 +163,3 @@ );

return {
'Content-Type': 'application/vnd.api+json',
"Content-Type": "application/vnd.api+json",
Authorization: `Bearer ${authorizationToken}`

@@ -167,3 +169,3 @@ };

return {
'Content-Type': 'application/vnd.api+json'
"Content-Type": "application/vnd.api+json"
};

@@ -188,6 +190,3 @@ }

if (!response.ok) {
const error = map(
json.errors,
error => new MPXAPIError(error)
);
const error = map(json.errors, error => new MPXAPIError(error));
globalResponseHandler.invoke(error);

@@ -198,8 +197,9 @@ return Promise.reject(error);

if (deserialize) {
const JSONAPIDeserializer = require('jsonapi-serializer').Deserializer;
const JSONAPIDeserializer = require("jsonapi-serializer").Deserializer;
const opts = {
keyForAttribute: 'camelCase'
keyForAttribute: "camelCase"
};
return new JSONAPIDeserializer(opts).deserialize(json)
return new JSONAPIDeserializer(opts)
.deserialize(json)
.then(deserializedData => {

@@ -226,3 +226,3 @@ globalResponseHandler.invoke(null, deserializedData);

*/
Root: '/',
Root: "/",
/**

@@ -232,3 +232,3 @@ * Path to contract resources.

*/
Contracts: '/contracts',
Contracts: "/contracts",
/**

@@ -238,3 +238,3 @@ * Path to fee receipeint resources.

*/
FeeRecipients: '/fee_recipients',
FeeRecipients: "/fee_recipients",
/**

@@ -244,3 +244,3 @@ * Path to fills resources.

*/
Fills: '/fills',
Fills: "/fills",
/**

@@ -250,3 +250,3 @@ * Path to perform jwt authentication.

*/
JWT: '/json_web_tokens',
JWT: "/json_web_tokens",
/**

@@ -256,3 +256,3 @@ * Path to profile of current authenticated user.

*/
Me: '/me',
Me: "/me",
/**

@@ -262,3 +262,3 @@ * Path to user notifications

*/
Notifications: '/notifications',
Notifications: "/notifications",
/**

@@ -268,3 +268,3 @@ * Path to orderbook resources.

*/
OrderBook: '/orderbooks',
OrderBook: "/orderbooks",
/**

@@ -274,3 +274,3 @@ * Path to order resources on the API.

*/
Orders: '/orders',
Orders: "/orders",
/**

@@ -280,8 +280,13 @@ * Path to asset rates in the MPX Ecosystem.

*/
Rates: '/rates',
Rates: "/rates",
/**
* Path to fetch Position Token Events on the API.
*
*/
PositionTokenEvents: "/position_token_events",
/**
* Path to API settings
*
*/
Settings: '/settings',
Settings: "/settings",
/**

@@ -291,3 +296,3 @@ * Path to fetch token pairs on the API.

*/
TokenPairs: '/token_pairs',
TokenPairs: "/token_pairs",
/**

@@ -297,3 +302,8 @@ * Path to fetch User Settings on the API.

*/
UserSettings: '/user_settings'
UserSettings: "/user_settings",
/**
* Path to fetch User Rewards on the API.
*
*/
UserRewards: "/user_rewards"
};

@@ -341,4 +351,6 @@

setGlobalResponseHandler(handler) {
if (handler !== null && typeof handler !== 'function') {
throw new Error('global response handler must either be null or a function.');
if (handler !== null && typeof handler !== "function") {
throw new Error(
"global response handler must either be null or a function."
);
}

@@ -367,3 +379,3 @@

return fetch(url(path, filterString, id), {
method: 'GET',
method: "GET",
headers: createHeader(authorizationToken)

@@ -394,3 +406,3 @@ }).then(jsonAPIResponseHandler(deserialize));

return fetch(url(path, filterString, id), {
method: 'POST',
method: "POST",
headers: createHeader(authorizationToken),

@@ -422,3 +434,3 @@ body: jsonAPIRequestHandler(path, body, serializeRequest)

return fetch(url(path, filterString, id), {
method: 'PATCH',
method: "PATCH",
headers: createHeader(authorizationToken),

@@ -450,3 +462,3 @@ body: jsonAPIRequestHandler(path, body, serializeRequest)

return fetch(url(path, filterString, id), {
method: 'PUT',
method: "PUT",
headers: createHeader(authorizationToken),

@@ -475,3 +487,3 @@ body: jsonAPIRequestHandler(path, body, serializeRequest)

return fetch(url(path, filterString, id), {
method: 'DELETE',
method: "DELETE",
headers: createHeader(authorizationToken)

@@ -485,3 +497,3 @@ }).then(jsonAPIResponseHandler(deserialize));

*/
Path,
Path
};
{
"name": "@marketprotocol/mpx-api-client",
"version": "0.14.0",
"version": "1.0.0",
"description": "Javascript client for communicating with the MPX API",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -0,1 +1,3 @@

<img src="https://github.com/MARKETProtocol/website/blob/develop/src/assets/images/MARKETProtocol-Light.png?raw=true" align="middle">
# MPX API Client

@@ -2,0 +4,0 @@ [![Build Status](https://travis-ci.com/MARKETProtocol/mpx-api-client.svg?branch=master)](https://travis-ci.com/MARKETProtocol/mpx-api-client)

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