Comparing version 0.1.9 to 0.1.10
@@ -10,3 +10,3 @@ 'use strict'; | ||
module.exports = function(blesta){ | ||
var _ = require('lodash'); | ||
const _ = require('lodash'); | ||
@@ -13,0 +13,0 @@ return { |
@@ -8,3 +8,3 @@ 'use strict'; | ||
module.exports = function(blesta){ | ||
var _ = require('lodash'); | ||
const _ = require('lodash'); | ||
@@ -11,0 +11,0 @@ return { |
@@ -8,3 +8,3 @@ 'use strict'; | ||
module.exports = function(blesta){ | ||
var _ = require('lodash'); | ||
const _ = require('lodash'); | ||
@@ -11,0 +11,0 @@ return { |
@@ -8,3 +8,3 @@ 'use strict'; | ||
module.exports = function(blesta){ | ||
var _ = require('lodash'); | ||
const _ = require('lodash'); | ||
@@ -11,0 +11,0 @@ return { |
@@ -8,3 +8,3 @@ 'use strict'; | ||
module.exports = function(blesta){ | ||
var _ = require('lodash'); | ||
const _ = require('lodash'); | ||
@@ -11,0 +11,0 @@ return { |
@@ -8,3 +8,3 @@ 'use strict'; | ||
module.exports = function(blesta){ | ||
var _ = require('lodash'); | ||
const _ = require('lodash'); | ||
@@ -11,0 +11,0 @@ return { |
@@ -8,3 +8,3 @@ 'use strict'; | ||
module.exports = function(blesta){ | ||
var _ = require('lodash'); | ||
const _ = require('lodash'); | ||
@@ -11,0 +11,0 @@ return { |
@@ -10,3 +10,3 @@ 'use strict'; | ||
module.exports = function(blesta){ | ||
var _ = require('lodash'); | ||
const _ = require('lodash'); | ||
@@ -13,0 +13,0 @@ return { |
@@ -10,3 +10,3 @@ 'use strict'; | ||
module.exports = function(blesta){ | ||
var _ = require('lodash'); | ||
const _ = require('lodash'); | ||
@@ -13,0 +13,0 @@ return { |
@@ -10,3 +10,3 @@ 'use strict'; | ||
module.exports = function(blesta){ | ||
var _ = require('lodash'); | ||
const _ = require('lodash'); | ||
@@ -13,0 +13,0 @@ return { |
@@ -8,3 +8,3 @@ 'use strict'; | ||
module.exports = function(blesta){ | ||
var _ = require('lodash'); | ||
const _ = require('lodash'); | ||
@@ -11,0 +11,0 @@ return { |
@@ -8,3 +8,3 @@ 'use strict'; | ||
module.exports = function(blesta){ | ||
var _ = require('lodash'); | ||
const _ = require('lodash'); | ||
@@ -11,0 +11,0 @@ return { |
@@ -8,3 +8,3 @@ 'use strict'; | ||
module.exports = function(blesta){ | ||
var _ = require('lodash'); | ||
const _ = require('lodash'); | ||
@@ -11,0 +11,0 @@ return { |
'use strict'; | ||
var path = require('path'), | ||
const path = require('path'), | ||
util = require('util'), | ||
fs = require('fs'); | ||
var _ = require('lodash'), | ||
const _ = require('lodash'), | ||
request = require('request'), | ||
moment = require('moment'); | ||
var blesta = function(options){ | ||
const blesta = function(options){ | ||
if(!(this instanceof blesta)){ | ||
@@ -56,9 +56,14 @@ return new blesta(options); | ||
} | ||
var message = this.errors[code]; | ||
let message = this.errors[code]; | ||
if(data && data.message){ | ||
message = data.message; | ||
} | ||
var error = new Error(message); | ||
const error = new Error(message); | ||
error.name = 'blestaError'; | ||
error.code = code; | ||
// check if data is still somehow a string (bad HTML response?) | ||
if(typeof(data) === 'string'){ | ||
data = {body: data}; | ||
} | ||
error.data = _.omit(data || {}, ['message']); | ||
@@ -69,3 +74,3 @@ return error; | ||
this.request = function(method, url, data, callback){ | ||
var self = this; | ||
const self = this; | ||
if(data && !callback){ | ||
@@ -79,3 +84,3 @@ callback = data; | ||
} | ||
var req = { | ||
let req = { | ||
url: util.format('%s/api%s.json', options.url, url), | ||
@@ -113,7 +118,11 @@ auth: options.auth, | ||
return callback(self.error('blesta.maintenance', body)); | ||
case 200: | ||
case 200:{ | ||
if(typeof(body) === undefined){ | ||
return callback(self.error('blesta.error')); | ||
} | ||
var response = body && body.response || {}; | ||
if(res.headers && res.headers['content-type'] && !res.headers['content-type'].includes('application/json')){ | ||
// not a valid JSON response | ||
return callback(self.error('blesta.error', body)); | ||
} | ||
const response = body && body.response || {}; | ||
if(response === undefined){ | ||
@@ -125,2 +134,3 @@ return callback(self.error('blesta.error', body)); | ||
return callback(null, response, res); | ||
} | ||
default: | ||
@@ -133,5 +143,5 @@ return callback(self.error('blesta.not_handled', body)); | ||
var self = this; | ||
const self = this; | ||
_.each(fs.readdirSync(__dirname + '/api'), function(folder){ | ||
var dir = __dirname + '/api/' + folder; | ||
const dir = __dirname + '/api/' + folder; | ||
_.each(fs.readdirSync(dir), function(file){ | ||
@@ -138,0 +148,0 @@ self[path.basename(file, '.js')] = require(dir + '/' + file)(self); |
{ | ||
"name": "blesta", | ||
"version": "0.1.9", | ||
"version": "0.1.10", | ||
"description": "Unofficial API Wrapper for the Blesta billing platform", | ||
@@ -13,2 +13,3 @@ "repository": { | ||
"lint": "eslint .", | ||
"lint:fix": "eslint . --fix", | ||
"precommit": "lint" | ||
@@ -26,12 +27,12 @@ }, | ||
"dependencies": { | ||
"lodash": "^4.17.14", | ||
"lodash": "^4.17.15", | ||
"moment": "^2.24.0", | ||
"request": "^2.88.0" | ||
"request": "^2.88.2" | ||
}, | ||
"devDependencies": { | ||
"eslint": "6.0.1", | ||
"eslint-config-nodecraft": "1.7.1", | ||
"eslint-plugin-json": "1.4.0", | ||
"eslint-plugin-node": "9.1.0" | ||
"eslint": "6.8.0", | ||
"eslint-config-nodecraft": "3.0.2", | ||
"eslint-plugin-json": "2.1.1", | ||
"eslint-plugin-node": "11.1.0" | ||
} | ||
} |
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
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
39918
1177
Updatedlodash@^4.17.15
Updatedrequest@^2.88.2