Socket
Socket
Sign inDemoInstall

good

Package Overview
Dependencies
Maintainers
6
Versions
95
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

good - npm Package Compare versions

Comparing version 8.1.1 to 8.1.2

CHANGELOG.md

101

lib/index.js
'use strict';
// Load modules
const Hoek = require('hoek');
const Joi = require('joi');
const Schema = require('./schema');
const Monitor = require('./monitor');
const internals = {
onPostStop(monitor) {
return (server, h) => {
const internals = {};
return monitor.stop();
};
internals.reporters = [
Joi.object({
pipe: Joi.func().required(),
start: Joi.func()
})
.unknown(),
Joi.string()
.valid('stdout', 'stderr'),
Joi.object({
module: Joi.alternatives().try(Joi.string(), Joi.func()).required(),
name: Joi.string(),
args: Joi.array().default([])
})
];
internals.schema = Joi.object({
includes: Joi.object({
request: Joi.array().items(Joi.string().valid('headers', 'payload')).default([]),
response: Joi.array().items(Joi.string().valid('headers', 'payload')).default([])
})
.default({
request: [],
response: []
}),
reporters: Joi.object()
.pattern(/./, Joi.array().items(...internals.reporters))
.default({}),
extensions: Joi.array()
.items(Joi.string().invalid('log', 'ops', 'request', 'response'))
.default([]),
ops: Joi.alternatives([
Joi.object(),
Joi.bool().allow(false)
])
.default({
config: {},
interval: 15000
})
})
.unknown(false);
exports.plugin = {
pkg: require('../package.json'),
requirements: {
hapi: '>=17.0.0'
},
onPreStart(monitor, options) {
register: function (server, options) {
return (server, h) => {
const settings = Joi.attempt(options, internals.schema);
const monitor = new Monitor(server, settings);
const interval = options.ops.interval;
monitor.startOps(interval);
};
server.ext('onPostStop', internals.onPostStop(monitor));
server.ext('onPreStart', internals.onPreStart(monitor, settings));
monitor.start();
}
};
exports.register = (server, options) => {
const result = Joi.validate(options, Schema.monitor);
Hoek.assert(!result.error, 'Invalid', 'monitorOptions', 'options', result.error);
internals.onPostStop = function (monitor) {
const monitor = new Monitor(server, result.value);
server.ext([{
type: 'onPostStop',
method: internals.onPostStop(monitor)
}, {
type: 'onPreStart',
method: internals.onPreStart(monitor, result.value)
}]);
return (server, h) => {
monitor.start();
return monitor.stop();
};
};
exports.pkg = require('../package.json');
internals.onPreStart = function (monitor, options) {
return (server, h) => {
const interval = options.ops.interval;
monitor.startOps(interval);
};
};
'use strict';
// Load modules
const Os = require('os');

@@ -15,4 +13,2 @@

// Declare internals
const internals = {

@@ -23,3 +19,5 @@ host: Os.hostname(),

class Monitor {
module.exports = internals.Monitor = class {
constructor(server, options) {

@@ -69,3 +67,2 @@

};
}

@@ -80,6 +77,6 @@

internals.forOwn(this.settings.reporters, (streamsSpec, reporterName) => {
for (const reporterName in this.settings.reporters) {
const streamsSpec = this.settings.reporters[reporterName];
if (!streamsSpec.length) {
return;
continue;
}

@@ -92,2 +89,3 @@

// Already created stream
if (typeof spec.pipe === 'function') {

@@ -98,3 +96,4 @@ streamObjs.push(spec);

// if this is stderr or stdout
// If this is stderr or stdout
if (process[spec]) {

@@ -126,3 +125,3 @@ streamObjs.push(process[spec]);

});
});
}

@@ -132,2 +131,3 @@ this._state.report = true;

// Initialize Events
this._server.events.on('log', this._logHandler);

@@ -144,6 +144,6 @@ this._server.events.on({ name: 'request', channels: ['error'] }, this._errorHandler);

// Events can not be any of ['log', 'ops', 'request', 'response', 'tail']
for (let i = 0; i < this.settings.extensions.length; ++i) {
const event = this.settings.extensions[i];
this._server.events.on(this.settings.extensions[i], (...args) => {
for (const event of this.settings.extensions) {
this._server.events.on(event, (...args) => {
const payload = {

@@ -154,2 +154,3 @@ event,

};
this.push(() => Object.assign({}, payload));

@@ -184,13 +185,2 @@ });

}
}
module.exports = Monitor;
internals.forOwn = (obj, func) => {
const keys = Object.keys(obj);
for (let i = 0; i < keys.length; ++i) {
const key = keys[i];
func(obj[key], key);
}
};
'use strict';
// Load modules
const Stream = require('stream');
const Stream = require('stream');
const Hoek = require('hoek');
// Declare internals
const internals = {};
internals.extractConfig = function (request) {

@@ -17,4 +16,7 @@

// Payload for "log" events
class ServerLog {
exports.ServerLog = class {
constructor(event) {

@@ -29,7 +31,9 @@

}
}
};
// Payload for "error" events
class RequestError {
exports.RequestError = class {
constructor(reqOptions, request, requestError) {

@@ -50,14 +54,15 @@

}
toJSON() {
const result = Object.assign({}, this, {
error: this.error.output.payload.message
});
const result = Object.assign({}, this, { error: this.error.output.payload.message });
return result;
}
}
};
// Payload for "response" events
class RequestSent {
exports.RequestSent = class {
constructor(reqOptions, resOptions, request, server) {

@@ -80,2 +85,5 @@

this.httpVersion = request.raw.req.httpVersion;
this.route = request.route.path;
this.log = request.route.settings.log.collect ? request.logs : [];
this.source = {

@@ -86,8 +94,3 @@ remoteAddress: request.info.remoteAddress,

};
this.route = request.route.path;
/* $lab:coverage:off$ */
this.log = (request.route.settings.log === false ? [] : request.logs); // Explicitly compare to false for hapi < v15
/* $lab:coverage:on$ */
this.tags = request.route.settings.tags;

@@ -103,16 +106,21 @@

if (resOptions.headers && request.response) {
this.responseHeaders = request.response.headers;
if (request.response) {
if (resOptions.headers) {
this.responseHeaders = request.response.headers;
}
if (resOptions.payload) {
this.responsePayload = request.response.source;
}
}
if (resOptions.payload && request.response) {
this.responsePayload = request.response.source;
}
this.config = internals.extractConfig(request);
}
}
};
// Payload for "ops" events
class Ops {
exports.Ops = class {
constructor(ops) {

@@ -124,2 +132,3 @@

this.pid = process.pid;
this.os = {

@@ -130,2 +139,3 @@ load: ops.osload,

};
this.proc = {

@@ -136,2 +146,3 @@ uptime: ops.psup,

};
this.load = {

@@ -144,7 +155,9 @@ requests: ops.requests,

}
}
};
// Payload for "request" events via request.log
class RequestLog {
exports.RequestLog = class {
constructor(reqOptions, request, event) {

@@ -167,5 +180,7 @@

}
}
};
class NoOp extends Stream.Transform {
exports.NoOp = class extends Stream.Transform {
constructor() {

@@ -175,2 +190,3 @@

}
_transform(value, encoding, callback) {

@@ -180,17 +196,2 @@

}
}
const timeout = function (ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
};
module.exports = {
ServerLog,
RequestError,
Ops,
RequestLog,
RequestSent,
NoOp,
timeout
};
{
"name": "good",
"description": "Server and process monitoring plugin",
"version": "8.1.1",
"version": "8.1.2",
"repository": "git://github.com/hapijs/good",

@@ -15,24 +15,18 @@ "main": "lib/index.js",

],
"engines": {
"node": ">=8.0.0"
},
"dependencies": {
"hoek": "5.x.x",
"joi": "13.x.x",
"hoek": "6.x.x",
"joi": "14.x.x",
"oppsy": "2.x.x",
"pumpify": "1.3.x"
},
"peerDependencies": {
"hapi": ">=17.x.x"
},
"devDependencies": {
"code": "5.x.x",
"hapi": "17.x.x",
"lab": "15.x.x",
"lab": "18.x.x",
"wreck": "14.x.x"
},
"scripts": {
"test": "lab -m 5000 -t 100 -v -La code"
"test": "lab -m 5000 -t 100 -L -a code"
},
"license": "BSD-3-Clause"
}

@@ -7,3 +7,3 @@ ![good Logo](images/good.png)

Lead Maintainer: [Adam Bretz](https://github.com/arb)
Lead Maintainer: [Open position](https://github.com/hapijs/good/issues/589)

@@ -10,0 +10,0 @@ *good 8 only supports hapi 17+ for hapi 16 please use good 7*

Sorry, the diff of this file is not supported yet

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