Comparing version 0.3.3 to 0.3.4
@@ -43,5 +43,8 @@ /** | ||
var original = {}; | ||
if(req.method === 'PUT' && req.data) { | ||
// update the current version before committing | ||
Object.keys(req.data).forEach(function (key) { | ||
original[key] = data[key]; | ||
data[key] = req.data[key]; | ||
@@ -52,3 +55,3 @@ }) | ||
// exec handler | ||
err = exec(handler, data, me); | ||
err = exec(handler, data, me, original); | ||
@@ -66,27 +69,55 @@ // without err, commit any changes | ||
function exec(src, data, session) { | ||
var fn, state, serr = sanitize(src); | ||
function exec(src, data, session, original) { | ||
var fn | ||
, state = {} | ||
, errors = {} | ||
, serr = sanitize(src) | ||
; | ||
if(serr) return {handler: serr}; | ||
// original fallback | ||
original = original || {}; | ||
// fail on sanitize err | ||
if(serr) return {message: serr}; | ||
function error(key, val) { | ||
errors[key] = val || true; | ||
} | ||
function cancel(msg, status) { | ||
state.status = status || 400; | ||
throw msg; | ||
} | ||
function hide(property) { | ||
delete data[property]; | ||
} | ||
function protect(property) { | ||
if(data[property]) data[property] = original[property] || undefined; | ||
} | ||
// wrap with a function | ||
src = 'function() {' + src + '}'; | ||
src = 'function(me) {' + src + '}'; | ||
try { | ||
fn = eval('('+ src +')'); | ||
state = fn.call(data, session); | ||
fn.call(data, session); | ||
} catch(e) { | ||
state = {status: 500, error: e}; | ||
state.status = state.status || 500; | ||
if(typeof e == 'string') { | ||
state.message = e; | ||
} else { | ||
state.message = e.message; | ||
} | ||
} | ||
// handle state | ||
if(state === false) { | ||
state = {status: 401}; | ||
} else if(state === true) { | ||
state = undefined; | ||
} else if(state && typeof state != 'object' || Array.isArray(state)) { | ||
state = {error: state}; | ||
// if there are errors attach them to state | ||
if(Object.keys(errors).length) { | ||
state.errors = errors; | ||
} | ||
return state; | ||
if(Object.keys(state).length) { | ||
return state; | ||
} | ||
} | ||
@@ -93,0 +124,0 @@ |
@@ -39,2 +39,7 @@ /** | ||
; | ||
// for non files, default to application/json | ||
if(!isJSON && req.url.indexOf('.') === -1) { | ||
isJSON = true; | ||
} | ||
@@ -123,8 +128,4 @@ // only buffer JSON | ||
server.error(function (err, req, res, next) { | ||
if(typeof err == 'object' && !(err instanceof Error)) { | ||
res.statusCode = err.status || 400; | ||
res.send({error: err}); | ||
} else { | ||
res.send(err); | ||
} | ||
res.statusCode = err.status || 400; | ||
res.send(err); | ||
}); | ||
@@ -131,0 +132,0 @@ |
{ | ||
"author": "Ritchie Martori", | ||
"name": "deployd", | ||
"version": "0.3.3", | ||
"version": "0.3.4", | ||
"repository": { | ||
@@ -6,0 +6,0 @@ "url": "git://github.com/deployd/deployd.git" |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
3518832
5315
1