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

hapi

Package Overview
Dependencies
Maintainers
3
Versions
295
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hapi - npm Package Compare versions

Comparing version 0.15.1 to 0.15.2

0

lib/composer.js

@@ -0,0 +0,0 @@ // Load modules

36

lib/pack.js

@@ -97,3 +97,3 @@ // Load modules

['log', 'request', 'response', 'tail'].forEach(function (event) {
['log', 'request', 'response', 'tail', 'internalError'].forEach(function (event) {

@@ -108,29 +108,2 @@ server.on(event, function (request, data) {

internals.Pack.prototype.validate = function (plugin) {
Utils.assert(plugin, 'Missing plugin');
if (!plugin.name) {
return new Error('Plugin missing name');
}
if (plugin.name === '?') {
return new Error('Plugin name cannot be \'?\'');
}
if (!plugin.version) {
return new Error('Plugin missing version');
}
if (!plugin.register ||
typeof plugin.register !== 'function') {
return new Error('Plugin missing register() method');
}
// Valid
return null;
};
internals.Pack.prototype.register = function (plugin/*, [options], callback */) {

@@ -156,6 +129,7 @@

Utils.assert(!this._env[plugin.name], 'Plugin already registered: ' + plugin.name);
Utils.assert(plugin.name, 'Plugin missing name');
Utils.assert(plugin.name !== '?', 'Plugin name cannot be \'?\'');
Utils.assert(plugin.version, 'Plugin missing version');
Utils.assert(plugin.register && typeof plugin.register === 'function', 'Plugin missing register() method');
var invalid = this.validate(plugin);
Utils.assert(!invalid, invalid && invalid.message);
var dependencies = _dependencies || {};

@@ -162,0 +136,0 @@

120

lib/request.js

@@ -145,4 +145,5 @@ // Load modules

Utils.assert(method, 'method must be provided');
this.method = method.toLowerCase();
if (method) {
this.method = method.toLowerCase();
}
};

@@ -286,5 +287,5 @@

func(self, next);
},
},
function (err) {
self._reply(err);

@@ -337,6 +338,3 @@ });

Response._respond(self.response, self, function () {
return finalize();
});
Response._respond(self.response, self, finalize);
};

@@ -346,2 +344,9 @@

if (self.response &&
((self.response.isBoom && self.response.response.code === 500) ||
(self.response.varieties && self.response.varieties.error && self.response._code === 500))) {
self.server.emit('internalError', self, (self.response.isBoom ? self.response : self.response._err));
}
self.server.emit('response', self);

@@ -364,5 +369,5 @@

internals.queryExtensions = function (request, next) {
// JSONP
if (request.route.jsonp) {

@@ -374,3 +379,3 @@ var jsonp = request.query[request.route.jsonp];

}
request.jsonp = jsonp;

@@ -389,2 +394,4 @@ delete request.query[request.route.jsonp];

// All the 'reply' methods execute inside a protected domain and can safetly throw
var response = null;

@@ -469,10 +476,4 @@

internals.Request.prototype._prerequisites = function (next) {
internals.Request.bindPre = function (pre) {
var self = this;
if (this._route.prerequisites.length === 0) {
return next();
}
/*

@@ -486,46 +487,28 @@ {

var parallelFuncs = [];
var serialFuncs = [];
return function (request, callback) {
var fetch = function (pre) {
Ext.runProtected(request.log.bind(request), 'pre', callback, function (run, next) {
return function (callback) {
var timer = new Utils.Timer();
pre.method(self, function (result) {
var finalize = function (result) {
if (result instanceof Error) {
self.log(['prerequisites', 'error'], { msec: timer.elapsed(), assign: pre.assign, mode: pre.mode, error: result });
return callback(result);
request.log(['prerequisites', 'error'], { msec: timer.elapsed(), assign: pre.assign, mode: pre.mode, error: result });
return next(result);
}
self.log(['prerequisites'], { msec: timer.elapsed(), assign: pre.assign, mode: pre.mode });
request.log(['prerequisites'], { msec: timer.elapsed(), assign: pre.assign, mode: pre.mode });
if (pre.assign) {
self.pre[pre.assign] = result;
request.pre[pre.assign] = result;
}
callback();
});
};
};
for (var i = 0, il = self._route.prerequisites.length; i < il; ++i) {
return next();
};
var pre = self._route.prerequisites[i];
var list = (pre.mode === 'parallel' ? parallelFuncs : serialFuncs);
list.push(fetch(pre));
}
run(function () {
Async.series([
function (callback) {
Async.parallel(parallelFuncs, callback);
},
function (callback) {
Async.series(serialFuncs, callback);
}
], function (err, results) {
return next(err);
});
pre.method(request, finalize);
});
});
};
};

@@ -570,2 +553,31 @@

var prerequisites = function (callback) {
if (!request._route.prerequisites.parallel.length &&
!request._route.prerequisites.serial.length) {
return callback();
}
Async.series([
function (nextSet) {
Async.forEach(request._route.prerequisites.parallel, function (pre, nextPre) {
pre(request, nextPre);
}, nextSet);
},
function (nextSet) {
Async.forEachSeries(request._route.prerequisites.serial, function (pre, nextPre) {
pre(request, nextPre);
}, nextSet);
}
], function (err, results) {
return callback(err);
});
};
var generate = function (callback) {

@@ -575,3 +587,3 @@

request._prerequisites(function (err) {
prerequisites(function (err) {

@@ -583,3 +595,3 @@ if (err) {

Ext.runProtected(log, 'handler', callback, function (run, next) {
var timer = new Utils.Timer();

@@ -599,3 +611,3 @@

if (request._route.cache.rule.strict) {
Utils.assert(response.varieties.cacheable, 'Attempted to cache non-cacheable item');
Utils.assert(response.varieties.cacheable, 'Attempted to cache non-cacheable item'); // Caught by the runProtected
}

@@ -610,3 +622,3 @@

run(function () {
switch (request.route.handler.length) {

@@ -613,0 +625,0 @@ case 0: // function: () this: request this.reply + properties

@@ -19,2 +19,3 @@ // Load modules

if (options.isBoom) {
this._err = options;
options = options.response;

@@ -21,0 +22,0 @@ }

@@ -0,0 +0,0 @@ // Load modules

@@ -93,4 +93,2 @@ // Load modules

Utils.assert(response && (response.variety || response.isBoom), 'Invalid response object'); // Safety
if (onSend) {

@@ -97,0 +95,0 @@ response.send = function () {

@@ -0,0 +0,0 @@ // Load modules

@@ -11,2 +11,3 @@ // Load modules

var Views = require('./views');
var Request = require('./request');

@@ -36,3 +37,3 @@

Utils.assert(!err, 'Route options are invalid: ' + err, true);
Utils.assert(!err, 'Route options are invalid: ' + err);
});

@@ -62,3 +63,3 @@

Utils.assert(!this.settings.jsonp || typeof this.settings.jsonp === 'string', 'Bad route JSONP parameter name');
// Authentication configuration

@@ -129,38 +130,43 @@

this.prerequisites = [];
if (this.settings.pre) {
for (var i = 0, il = this.settings.pre.length; i < il; ++i) {
this.prerequisites = {
parallel: [],
serial: []
};
var pre = (typeof this.settings.pre[i] === 'object' ? this.settings.pre[i] : { method: this.settings.pre[i] });
Utils.assert(pre.method, 'Prerequisite config missing method');
Utils.assert(typeof pre.method === 'function' || typeof pre.method === 'string', 'Prerequisite method must be a function or helper name');
(this.settings.pre || []).forEach(function (pre) {
pre.mode = pre.mode || 'serial';
Utils.assert(pre.mode === 'serial' || pre.mode === 'parallel', 'Unknown prerequisite mode: ' + pre.mode);
if (typeof pre !== 'object') {
pre = { method: pre };
}
if (typeof pre.method === 'string') {
var preMethodParts = pre.method.match(/^(\w+)(?:\s*)\((\s*\w+(?:\.\w+)*\s*(?:\,\s*\w+(?:\.\w+)*\s*)*)?\)$/);
Utils.assert(preMethodParts, 'Invalid prerequisite string method syntax');
var helper = preMethodParts[1];
Utils.assert(preMethodParts && this.server.helpers[helper], 'Unknown server helper method in prerequisite string');
pre.assign = pre.assign || helper;
var helperArgs = preMethodParts[2].split(/\s*\,\s*/);
Utils.assert(pre.method, 'Prerequisite config missing method');
Utils.assert(typeof pre.method === 'function' || typeof pre.method === 'string', 'Prerequisite method must be a function or helper name');
pre.method = function (helper, helperArgs, request, next) {
pre.mode = pre.mode || 'serial';
Utils.assert(pre.mode === 'serial' || pre.mode === 'parallel', 'Unknown prerequisite mode: ' + pre.mode);
var args = [];
helperArgs.forEach(function (arg) {
if (typeof pre.method === 'string') {
var preMethodParts = pre.method.match(/^(\w+)(?:\s*)\((\s*\w+(?:\.\w+)*\s*(?:\,\s*\w+(?:\.\w+)*\s*)*)?\)$/);
Utils.assert(preMethodParts, 'Invalid prerequisite string method syntax');
var helper = preMethodParts[1];
Utils.assert(preMethodParts && self.server.helpers[helper], 'Unknown server helper method in prerequisite string');
pre.assign = pre.assign || helper;
var helperArgs = preMethodParts[2].split(/\s*\,\s*/);
args.push(Utils.reach(request, arg));
});
pre.method = function (helper, helperArgs, request, next) {
args.push(next);
request.server.helpers[helper].apply(null, args);
}.bind(null, helper, helperArgs);
}
var args = [];
helperArgs.forEach(function (arg) {
this.prerequisites.push(pre);
args.push(Utils.reach(request, arg));
});
args.push(next);
request.server.helpers[helper].apply(null, args);
}.bind(null, helper, helperArgs);
}
}
self.prerequisites[pre.mode].push(Request.bindPre(pre));
});
// Object handler

@@ -167,0 +173,0 @@

@@ -0,0 +0,0 @@ // Load modules

@@ -63,3 +63,3 @@ // Load modules

Utils.assert(!err, 'Invalid server options: ' + err, true);
Utils.assert(!err, 'Invalid server options: ' + err);
});

@@ -66,0 +66,0 @@

@@ -0,0 +0,0 @@ // Load modules

@@ -5,3 +5,3 @@ {

"homepage": "http://hapijs.com",
"version": "0.15.1",
"version": "0.15.2",
"author": "Eran Hammer <eran@hueniverse.com> (http://hueniverse.com)",

@@ -24,3 +24,3 @@ "contributors": [

"dependencies": {
"hoek": "0.6.x",
"hoek": "0.7.x",
"boom": "0.3.x",

@@ -32,3 +32,3 @@ "joi": "0.2.x",

"async": "0.1.x",
"request": "2.14.x",
"request": "2.16.x",
"formidable": "1.0.x",

@@ -35,0 +35,0 @@ "mime": "1.2.x",

@@ -12,3 +12,3 @@ <a href="https://github.com/spumko"><img src="https://raw.github.com/spumko/spumko/master/images/from.png" align="right" /></a>

Current version: **0.15.1**
Current version: **0.15.2**

@@ -15,0 +15,0 @@ [![Build Status](https://secure.travis-ci.org/spumko/hapi.png)](http://travis-ci.org/spumko/hapi)

@@ -265,42 +265,2 @@ // Load modules

it('invalidates missing name', function (done) {
var pack = new Hapi.Pack();
var err = pack.validate({ version: '0.0.0', register: function (pack, options, next) { next(); } });
expect(err).to.exist;
expect(err.message).to.equal('Plugin missing name');
done();
});
it('invalidates bad name', function (done) {
var pack = new Hapi.Pack();
var err = pack.validate({ name: '?', version: '0.0.0', register: function (pack, options, next) { next(); } });
expect(err).to.exist;
expect(err.message).to.equal('Plugin name cannot be \'?\'');
done();
});
it('invalidates missing version', function (done) {
var pack = new Hapi.Pack();
var err = pack.validate({ name: 'test', register: function (pack, options, next) { next(); } });
expect(err).to.exist;
expect(err.message).to.equal('Plugin missing version');
done();
});
it('invalidates missing register method', function (done) {
var pack = new Hapi.Pack();
var err = pack.validate({ name: 'test', version: '0.0.0' });
expect(err).to.exist;
expect(err.message).to.equal('Plugin missing register() method');
done();
});
it('extends onRequest point', function (done) {

@@ -307,0 +267,0 @@

@@ -56,2 +56,7 @@ // Load modules

var fetchException = function (request, next) {
a.b.c;
};
var getFetch1 = function (request) {

@@ -117,2 +122,13 @@

method: 'GET',
path: '/fetchException',
config: {
pre: [
{ method: fetch1, assign: 'm1', mode: 'parallel' },
{ method: fetchException, assign: 'm6' }
],
handler: getFetch2
}
},
{
method: 'GET',
path: '/user/{id}',

@@ -176,3 +192,3 @@ config: {

it('returns error is prerequisite returns error', function (done) {
it('returns error if prerequisite returns error', function (done) {

@@ -186,2 +202,11 @@ makeRequest('/fetch3', function (res) {

it('returns 500 if prerequisite throws', function (done) {
makeRequest('/fetchException', function (res) {
expect(res.code).to.equal(500);
done();
});
});
it('returns a user record using helper', function (done) {

@@ -188,0 +213,0 @@

@@ -103,14 +103,2 @@ // Load modules

it('throws an error when a null method is passed in', function (done) {
var fn = function () {
var request = new Request(server, _req, _res);
request._setMethod(null);
};
expect(fn).throws(Error, 'method must be provided');
done();
});
it('changes method with a lowercase version of the value passed in', function (done) {

@@ -117,0 +105,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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