adonis-kraken
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -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' | ||
} |
{ | ||
"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 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
51865
8
118
1
1
+ Addedrequest@^2.85.0
+ Addedajv@6.12.6(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@1.0.0(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcore-util-is@1.0.2(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@2.3.3(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedoauth-sign@0.9.0(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedpsl@1.13.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqs@6.5.3(transitive)
+ Addedrequest@2.88.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedverror@1.10.0(transitive)