New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@elevenyellow.com/switchain-api-client

Package Overview
Dependencies
Maintainers
6
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@elevenyellow.com/switchain-api-client - npm Package Compare versions

Comparing version 3.2.0 to 3.3.0

4

package.json
{
"name": "@elevenyellow.com/switchain-api-client",
"version": "3.2.0",
"version": "3.3.0",
"description": "client module to access switchains's api",

@@ -27,2 +27,3 @@ "main": "./src/index.js",

"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"eslint": "^5.6.0",

@@ -42,3 +43,2 @@ "eslint-config-airbnb": "^17.1.0",

"dependencies": {
"chai-as-promised": "^7.1.1",
"isomorphic-unfetch": "^3.0.0",

@@ -45,0 +45,0 @@ "query-string": "^6.2.0"

@@ -10,4 +10,7 @@ # Install

```js
const { init } = require("switchain-api-client");
const SwitchainApi = init({ apiKey: "xxx" });
const { init } = require('switchain-api-client')
const SwitchainApi = init({
apiKey: 'xxxxxxxx-yyyy-zzzz-0000-999999999999',
apiUrl: 'http://localhost:3020/rest/v1/' // optional
})
```

@@ -30,3 +33,3 @@

```js
const { info } = SwitchainApi.getMarketInfo();
const { info } = SwitchainApi.getMarketInfo()
```

@@ -45,3 +48,3 @@

offer: {
signature, expiryTs, pair, quote, maxLimit, minLimit;
signature, expiryTs, pair, quote, maxLimit, minLimit
}

@@ -55,4 +58,4 @@ }

const { offer } = SwitchainApi.getOffer({
pair: "ETH-DAI"
});
pair: 'ETH-DAI'
})
```

@@ -75,3 +78,3 @@

order: {
orderId, fromAmount, rate, exchangeAddress, toAddress, refundAddress;
orderId, fromAmount, rate, exchangeAddress, toAddress, refundAddress
}

@@ -90,3 +93,3 @@ }

signature
});
})
```

@@ -105,3 +108,3 @@

status: {
status, fromAmount, rate, exchangeAddress, toAddress, refundAddress, toTx;
status, fromAmount, rate, exchangeAddress, toAddress, refundAddress, toTx
}

@@ -114,3 +117,3 @@ }

```js
const { status } = SwitchainApi.getOrderStatus({ orderId });
const { status } = SwitchainApi.getOrderStatus({ orderId })
```

@@ -1,20 +0,11 @@

// const request = require("request-promise");
const fetch = require("isomorphic-unfetch");
const queryString = require("query-string");
const fetch = require('isomorphic-unfetch')
const queryString = require('query-string')
function getApiUrl({ mode = "prod" } = { mode: "prod" }) {
let apiUrl;
if (mode === "prod") {
apiUrl = "https://api.switchain.com/rest/v1/";
} else {
apiUrl = "https://api-testnet.switchain.com/rest/v1/";
}
// console.log("switchain-api-client.getApiUrl", { apiUrl, mode });
return apiUrl;
}
function init({ apiKey, mode = 'prod', apiUrl }) {
const finalApiUrl = apiUrl || getApiUrl({ mode })
function init({ apiKey, mode = "prod" }) {
return {
getMarketInfo: () => getMarketInfo({ apiKey, mode }),
getOffer: ({ pair, amount }) => getOffer({ pair, amount, apiKey, mode }),
getMarketInfo: () => getMarketInfo({ apiKey, apiUrl: finalApiUrl }),
getOffer: ({ pair, amount }) =>
getOffer({ pair, amount, apiKey, apiUrl: finalApiUrl }),
postOrder: ({ toAddress, refundAddress, pair, fromAmount, signature }) =>

@@ -28,41 +19,40 @@ postOrder({

apiKey,
mode
apiUrl: finalApiUrl
}),
getOrderStatus: ({ orderId }) => getOrderStatus({ orderId, apiKey, mode }),
getOrderStatus: ({ orderId }) =>
getOrderStatus({ orderId, apiKey, apiUrl: finalApiUrl }),
getOrdersInfo: ({ page, limit, sort }) =>
getOrdersInfo({ page, limit, sort, apiKey, mode })
};
getOrdersInfo({ page, limit, sort, apiKey, apiUrl: finalApiUrl })
}
}
async function getMarketInfo({ apiKey, mode }) {
const apiUrl = getApiUrl({ mode });
const uri = `${apiUrl}marketinfo/`;
async function getMarketInfo({ apiKey, apiUrl }) {
const uri = `${apiUrl}marketinfo/`
try {
const response = await fetch(uri, {
headers: { Authorization: `Bearer ${apiKey}` }
});
})
return response.json();
return response.json()
} catch (error) {
console.log(`switchainApiClient.getMarketInfo.error: ${error}`);
throw error;
console.log(`switchainApiClient.getMarketInfo.error: ${error}`)
throw error
}
}
async function getOffer({ pair, amount, apiKey, mode }) {
const apiUrl = getApiUrl({ mode });
async function getOffer({ pair, amount, apiKey, apiUrl }) {
const params = { pair }
if (amount) params.amount = amount
const params = { pair };
if (amount) params.amount = amount;
const uri = buildUrl({ url: `${apiUrl}offer/`, params });
const uri = buildUrl({ url: `${apiUrl}offer`, params })
try {
const response = await fetch(uri, {
headers: { Authorization: `Bearer ${apiKey}` }
});
})
return response.json();
return response.json()
} catch (error) {
console.log(`switchainApiClient.getOffer.error: ${error}`);
throw error;
console.log(`switchainApiClient.getOffer.error: ${error}`)
throw error
}

@@ -78,6 +68,5 @@ }

apiKey,
mode
apiUrl
}) {
const apiUrl = getApiUrl({ mode });
const uri = `${apiUrl}order/`;
const uri = `${apiUrl}order/`

@@ -89,55 +78,53 @@ const body = {

fromAmount
};
if (signature) body.signature = signature;
}
if (signature) body.signature = signature
try {
const response = await fetch(uri, {
method: "POST",
method: 'POST',
body: JSON.stringify(body),
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json"
'Content-Type': 'application/json'
}
});
})
return response.json();
return response.json()
} catch (error) {
console.log(`switchainApiClient.postOrder.error: ${error}`);
throw error;
console.log(`switchainApiClient.postOrder.error: ${error}`)
throw error
}
}
async function getOrderStatus({ orderId, apiKey, mode }) {
const apiUrl = getApiUrl({ mode });
const uri = `${apiUrl}order/${orderId}`;
async function getOrderStatus({ orderId, apiKey, apiUrl }) {
const uri = `${apiUrl}order/${orderId}`
try {
const response = await fetch(uri, {
headers: { Authorization: `Bearer ${apiKey}` }
});
})
return response.json();
return response.json()
} catch (error) {
console.log(`switchainApiClient.getOrderStatus.error: ${error}`);
throw error;
console.log(`switchainApiClient.getOrderStatus.error: ${error}`)
throw error
}
}
async function getOrdersInfo({ limit, page, sort, apiKey, mode }) {
const apiUrl = getApiUrl({ mode });
async function getOrdersInfo({ limit, page, sort, apiKey, apiUrl }) {
const params = {}
if (limit) params.limit = limit
if (page) params.page = page
if (sort) params.sort = sort
const params = {};
if (limit) params.limit = limit;
if (page) params.page = page;
if (sort) params.sort = sort;
const uri = buildUrl({ url: `${apiUrl}ordersinfo/`, params });
const uri = buildUrl({ url: `${apiUrl}ordersinfo/`, params })
try {
const response = await fetch(uri, {
headers: { Authorization: `Bearer ${apiKey}` }
});
})
return response.json();
return response.json()
} catch (error) {
console.log(`switchainApiClient.getOrdersInfo.error: ${error}`);
throw error;
console.log(`switchainApiClient.getOrdersInfo.error: ${error}`)
throw error
}

@@ -153,10 +140,15 @@ }

getOrdersInfo
};
}
// private
function getApiUrl({ mode = 'prod' } = { mode: 'prod' }) {
return mode === 'prod'
? 'https://api.switchain.com/rest/v1/'
: 'https://api-testnet.switchain.com/rest/v1/'
}
function buildUrl({ url, params }) {
const query = queryString.stringify(params);
const query = queryString.stringify(params)
return `${url}?${query}`;
return `${url}?${query}`
}
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