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

cardano-api

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cardano-api - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

test/test-cardano-errors.js

23

lib/cardano.js

@@ -8,16 +8,21 @@ const request = require('request')

// buildMethod returns a function that returns a promise
const buildMethod = endpoint => query => new Promise((resolve, reject) => {
let path = '', params = '', stopper
let path = '', params = '', badKey
if(query) {
// if trying to set a path in the query but path is not available for this
// endpoint, then reject
if(!endpoint.path && query.path) return reject(noPathAllowed)
params = Object.keys(query).reduce((str, key) => {
// if this is not a valid param for the endpoint, set the badKey
if(!endpoint.params.includes(key)) {
stopper = true
badKey = key
}
// if one of the keys matches a path, set the path for the url
if(paths.includes(key)) {

@@ -28,2 +33,3 @@ path = `/${query[key]}`

// tack on the current ket to the params string
str += `${key}=${query[key]}&`

@@ -34,9 +40,12 @@ return str

// if there are params add a '?' to the front and remove the trailing '&'
params = params ? `?${params.replace(/\&$/, '')}` : ''
if(stopper) return reject(`${stopper} is not a valid query to this endpoint`)
if(badKey) return reject(`${badKey} is not a valid query to this endpoint`)
}
// if the endpoint requires a path but it is not provided reject
if(endpoint.path && !path) return reject(noPathProvided)
// build the url
const url = `${api}${endpoint.url}${path}${params}`

@@ -46,3 +55,5 @@

if(err) reject(err)
if(res.statusCode === 404 || res.statusCode === 400) reject(res.statusMessage)
if(res.statusCode === 404 || res.statusCode === 400) {
reject(`${res.statusCode}: ${res.statusMessage}`)
}
if(body) resolve(JSON.parse(body))

@@ -49,0 +60,0 @@ })

{
"name": "cardano-api",
"version": "0.0.4",
"description": "Node promise wrapper for the Cardano Explorer API",
"version": "0.0.5",
"description": "Node wrapper for the Cardano Explorer API",
"main": "lib/cardano.js",

@@ -6,0 +6,0 @@ "scripts": {

# cardano-api
Promise wrapper for the [Cardano API](https://cardanodocs.com/technical/explorer/api/).
Wrapper for the [Cardano API](https://cardanodocs.com/technical/explorer/api/).

@@ -81,3 +81,2 @@ ```js

```js
const query = {

@@ -156,2 +155,2 @@ page: 1, // Optional

#### Thank You
##### Thank You
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