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

adonis-kraken

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

adonis-kraken - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

yarn.lock

7

config/kraken.js

@@ -13,4 +13,9 @@ 'use strict'

secret: Env.get('KRAKEN_SECRET') || null
}
},
/**
* The current Kraken API base URL
*/
base_api_url: 'https://api.kraken.io/v1'
}

5

package.json
{
"name": "adonis-kraken",
"version": "0.0.3",
"version": "0.0.4",
"description": "Simplifies working with Kraken.io (image optimisation service) through Adonis",

@@ -27,3 +27,6 @@ "main": "index.js",

"@adonisjs/sink": "^1.0.13"
},
"dependencies": {
"request": "^2.85.0"
}
}
'use strict'
const fs = require("fs")
const stream = require("stream")
const request = require("request")
const defaultConfig = require('../../config/kraken.js')

@@ -9,6 +13,72 @@

this.options = Config.merge('kraken', defaultConfig)
this.auth = {
api_key: this.options.api_key || '',
api_secret: this.options.secret || ''
}
this.api_url = this.options.base_api_url || 'https://api.kraken.io/v1'
}
/**
* Creates an HTTP response handler
*
* @param {Function} cb
*/
_createResponseHandler (cb) {
return function (err, res, body) {
if (err) return cb(err)
return (body.success === false)
? cb(new Error(body.message))
: cb(undefined, body)
}
}
/**
* Pass the given image URL along with credentials to Kraken API via HTTPS POST
*
* @param {Object} body
* @param {Function} cb
*/
url (body = {}, cb) {
body.auth = this.auth
request.post({
url: `${this.api_url}/url`,
json: true,
strictSSL: false,
body
}, this._createResponseHandler(cb))
}
/**
* Upload the given file along with credentials to Kraken API via HTTPS POST
*
* @param {Object} opts
* @param {Function} cb
*/
upload (opts = {}, cb) {
opts.auth = this.auth
let formData = {}
formData.file = (opts.file && opts.file instanceof stream.Stream)
? opts.file
: fs.createReadStream(opts.file)
delete opts.file
formData.data = JSON.stringify(opts)
request.post({
url: `${this.api_url}/upload`,
json: true,
strictSSL: false,
formData,
}, this._createResponseHandler(cb))
}
}
module.exports = Kraken
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