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.14 to 1.0.0

11

config/kraken.js

@@ -5,10 +5,15 @@ 'use strict'

const parseEnvBoolean = (val) => (val && (val.toLowerCase === 'true'))
module.exports = {
/**
* The access key credentials created through the Kraken dashboard
*/
api_key: Env.get('KRAKEN_API_KEY') || null,
api_secret: Env.get('KRAKEN_API_SECRET') || null
apiKey: Env.get('KRAKEN_API_KEY') || null,
apiSecret: Env.get('KRAKEN_API_SECRET') || null,
/**
* Enable Kraken's sandbox developer mode for testing purposes
*/
sandboxMode: parseEnvBoolean(Env.get('KRAKEN_SANDBOX_MODE')),
}

@@ -16,3 +16,3 @@ ## Register Provider

```
By default this configuration file is set up to read `KRAKEN_API_KEY` and `KRAKEN_API_SECRET` variables from your `.env` file so that they remain secret (as this file should **not** be included in your code repository!) however you are free to override this behaviour by modifying the `config/kraken.js` file and setting the `api_key` and `api_secret` properties there.
By default this configuration file is set up to read `KRAKEN_API_KEY` and `KRAKEN_API_SECRET` variables from your `.env` file so that they remain secret (as this file should **not** be included in your code repository!) however you are free to override this behaviour by modifying the `config/kraken.js` file and setting the `apiKey` and `apiSecret` properties there.

@@ -39,4 +39,2 @@ > **WARNING** - It is dangerous to leave your API credentials directly in `config/kraken.js` in a public code repository as anyone will be able to read/use them - do so at your own risk!

class MyController {
/**

@@ -54,3 +52,2 @@ * Optimize an image via a URL

/**

@@ -60,3 +57,2 @@ * Optimize an image via a file upload

async optimizeImageViaUpload ({ request }) {
// Get access to the uploaded file. We are using a method

@@ -81,3 +77,2 @@ // which means we do not need to save the file to our local

/**

@@ -90,4 +85,2 @@ * Get some quota stats based on the active API key/secret

}
}

@@ -94,0 +87,0 @@

{
"name": "adonis-kraken",
"version": "0.0.14",
"version": "1.0.0",
"description": "Simplifies working with Kraken.io (image optimisation service) through Adonis",

@@ -24,9 +24,9 @@ "main": "index.js",

"devDependencies": {
"@adonisjs/ace": "^5.0.0",
"@adonisjs/fold": "^4.0.5"
"@adonisjs/ace": "^5.0.8",
"@adonisjs/fold": "^4.0.9"
},
"dependencies": {
"axios": "^0.18.0",
"form-data": "^2.3.2"
"axios": "^0.19.0",
"form-data": "^2.5.0"
}
}
'use strict'
const { ServiceProvider } = require('@adonisjs/fold')
const { ServiceProvider } = require.main.require('@adonisjs/fold')
class KrakenProvider extends ServiceProvider {
register () {
this._registerKraken()
this._registerCommands()
}
boot () {
const ace = require('@adonisjs/ace')
ace.addCommand('Kraken:GetConfig')
}
_registerKraken () {

@@ -16,17 +25,6 @@ this.app.singleton('Kraken', (app) => {

_registerCommands () {
this.app.bind('Kraken:GetConfig', (app) => require('../commands/GetConfig'))
this.app.bind('Kraken:GetConfig', () => require('../commands/GetConfig'))
}
register () {
this._registerKraken()
this._registerCommands()
}
boot () {
const ace = require('@adonisjs/ace')
ace.addCommand('Kraken:GetConfig')
}
}
module.exports = KrakenProvider

@@ -5,4 +5,2 @@ # adonis-kraken

:exclamation: **WARNING! This package is heavily in development and is therefore unstable. It may not work correctly or at all. When it is working the way that it needs to I will bump it up to 0.1.0!**
## Installation

@@ -17,3 +15,3 @@ * Run `adonis install adonis-kraken` within your Adonis project

```
By default this configuration file is set up to read `KRAKEN_API_KEY` and `KRAKEN_API_SECRET` variables from your `.env` file so that they remain secret (as this file should **not** be included in your code repository!) however you are free to override this behaviour by modifying the `config/kraken.js` file and setting the `api_key` and `api_secret` properties there.
By default this configuration file is set up to read `KRAKEN_API_KEY` and `KRAKEN_API_SECRET` variables from your `.env` file so that they remain secret (as this file should **not** be included in your code repository!) however you are free to override this behaviour by modifying the `config/kraken.js` file and setting the `apiKey` and `apiSecret` properties there.

@@ -40,4 +38,2 @@ > **WARNING** - It is dangerous to leave your API credentials directly in `config/kraken.js` in a public code repository as anyone will be able to read/use them - do so at your own risk!

class MyController {
/**

@@ -55,3 +51,2 @@ * Optimize an image via a URL

/**

@@ -61,3 +56,2 @@ * Optimize an image via a file upload

async optimizeImageViaUpload ({ request }) {
// Get access to the uploaded file. We are using a method

@@ -82,3 +76,2 @@ // which means we do not need to save the file to our local

/**

@@ -91,4 +84,2 @@ * Get some quota stats based on the active API key/secret

}
}

@@ -95,0 +86,0 @@

'use strict'
const fs = require("fs")
const stream = require("stream")
const axios = require("axios")
const axios = require('axios')
const Config = use('Config')
const FormData = require('form-data')
const fs = require('fs')
const stream = require('stream')
const Config = use('Config')
class Kraken {
constructor (inputConfig) {

@@ -17,13 +15,65 @@ this.options = inputConfig.merge('kraken', Config.get('kraken'))

/**
* Attaches authentication data to request body
* Optimise image from URL
*
* @param {Object} body
* @param {Function} cb
*/
_attachAuth (body = {}) {
return body = {
async url (body = {}) {
try {
return axios.post('https://api.kraken.io/v1/url', this._attachConfig(body))
} catch (error) {
console.log(error)
return error
}
}
/**
* Optimise image from direct upload
*
* @param {Object} body
*/
async upload (body = {}) {
try {
let form = new FormData()
form.append('file', this._getStreamedFile(body.file), this._getFileName(this._getStreamedFile(body.file)))
delete body.file
form.append('data', JSON.stringify(this._attachConfig(body)))
return axios.post('https://api.kraken.io/v1/upload', form, this._getFormHeaders(form))
} catch (error) {
console.log(error)
return error
}
}
/**
* Get status for authenticated user (quota used/remaining etc)
*/
async userStatus (formatSizes = false) {
try {
let { data } = await axios.post('https://api.kraken.io/user_status', this._attachConfig())
if (formatSizes) {
data.quota_total = this._formatBytes({ bytes: data.quota_total })
data.quota_used = this._formatBytes({ bytes: data.quota_used })
data.quota_remaining = this._formatBytes({ bytes: data.quota_remaining })
}
return data
} catch (error) {
console.log(error)
return error
}
}
/**
* Attaches config data to request body
*
* @param {Object} body
*/
_attachConfig (body = {}) {
return {
auth: {
api_key: this.options.api_key || '',
api_secret: this.options.api_secret || ''
api_key: this.options.apiKey || this.options.api_key || '',
api_secret: this.options.apiSecret || this.options.api_secret || '',
},
...body
dev: this.options.sandboxMode,
...body,
}

@@ -72,56 +122,4 @@ }

}
/**
* Optimise image from URL
*
* @param {Object} body
* @param {Function} cb
*/
async url (body = {}) {
try {
return axios.post('https://api.kraken.io/v1/url', this._attachAuth(body))
} catch (error) {
console.log(error)
return error
}
}
/**
* Optimise image from direct upload
*
* @param {Object} body
*/
async upload (body = {}) {
try {
let form = new FormData()
form.append('file', this._getStreamedFile(body.file), this._getFileName(this._getStreamedFile(body.file)))
delete body.file
form.append('data', JSON.stringify(this._attachAuth(body)))
return axios.post('https://api.kraken.io/v1/upload', form, this._getFormHeaders(form))
} catch (error) {
console.log(error)
return error
}
}
/**
* Get status for authenticated user (quota used/remaining etc)
*/
async userStatus (formatSizes = false) {
try {
let { data } = await axios.post('https://api.kraken.io/user_status', this._attachAuth())
if (formatSizes) {
data.quota_total = this._formatBytes({ bytes: data.quota_total })
data.quota_used = this._formatBytes({ bytes: data.quota_used })
data.quota_remaining = this._formatBytes({ bytes: data.quota_remaining })
}
return data
} catch (error) {
console.log(error)
return error
}
}
}
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