Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
@magneds/hapi-plugin
Advanced tools
A convenience layer to easily create plugins for the Hapi ecosystem
The HapiPlugin package is a scoped packages, which means you'll have to include the scope during installation.
$ npm install --save @magneds/hapi-plugin
As with the installation, the scope is required to use the package as well.
const HapiPlugin = require('@magneds/hapi-plugin');
const plugin = new HapiPlugin(require('./package.json'));
module.exports = plugin.export;
The HapiPlugin module consist of getter and setter functions, so the API is mostly configurable setting properties.
constructor([{object}])
A HapiPlugin instance can easily be bootstrapped using a predefined object, this will allow for quick creation aswel as provide consistency by allowing the use of your module package json for the name and/or version information.
Any value can still be overwritten.
const HapiPlugin = require('@magneds/hapi-plugin');
const plugin = new HapiPlugin(require('./package.json'));
module.exports = plugin.exports;
Set the name for the plugin. There are no enforced limitations, though it is probably wise to adhere to the Hapi implied standards of using names consisting of lowercase characters separated by a dash, as this helps configuring dependencies.
const HapiPlugin = require('@magneds/hapi-plugin');
const plugin = new HapiPlugin(require('./package.json'));
plugin.name = 'my-plugin';
module.exports = plugin.exports;
Set the version for the plugin.
const HapiPlugin = require('@magneds/hapi-plugin');
const plugin = new HapiPlugin(require('./package.json'));
plugin.version = 'my-plugin';
module.exports = plugin.exports;
Set the register method for the plugin. This method is what Hapi will invoke when registering your plugin. When this method is invoced, you can be certain all dependencies are already loaded and ready.
const HapiPlugin = require('@magneds/hapi-plugin');
const plugin = new HapiPlugin(require('./package.json'));
plugin.register = async(server, options) {
await server.route({
method: 'GET',
path: '/my-plugin-route',
handler(request, h) {
return h.response('my-plugin response');
},
});
};
module.exports = plugin.exports;
Declare plugin dependencies to other plugins.
const HapiPlugin = require('@magneds/hapi-plugin');
const plugin = new HapiPlugin(require('./package.json'));
plugin.dependencies.push('my-other-plugin');
// or overwrite the dependencies entirely
plugin.dependencies = ['my-other-plugin'];
module.exports = plugin.exports;
Configure (default) options to be provided to the plugin on registration by Hapi. Upon setting new options, the previous values are not removed but instead the new values are added to the existing ones.
const HapiPlugin = require('@magneds/hapi-plugin');
const plugin = new HapiPlugin(require('./package.json'));
plugin.options = { foo: 'bar' };
plugin.options = { baz: 'qux' };
console.log(plugin.options); // { foo: 'bar', baz: 'qux' }
module.exports = plugin.exports;
Hapi allows for specification of vhost
and prefix
in a routes
settings. HapiPlugin lets you prepare either one using the routes
property (or simply set the vhost
and/or prefix
property);
const HapiPlugin = require('@magneds/hapi-plugin');
const plugin = new HapiPlugin(require('./package.json'));
plugin.routes = { prefix: '/my-prefix' };
console.log(plugin.routes); // { prefix: '/my-prefix' }
module.exports = plugin.exports;
Specify the prefix to use for all plugin registered routes. This is a very nice way to allow for modification to the routes registered by your plugin. HapiPlugin will take care of putting the prefix into the routes
object.
const HapiPlugin = require('@magneds/hapi-plugin');
const plugin = new HapiPlugin(require('./package.json'));
plugin.prefix = '/my-prefix';
console.log(plugin.prefix); // '/my-prefix'
console.log(plugin.routes); // { prefix: '/my-prefix' }
module.exports = plugin.exports;
Specify the vhost to use for all plugin registered routes. This is a convenient way to ensure the plugin routes exist only for specific vhosts.
const HapiPlugin = require('@magneds/hapi-plugin');
const plugin = new HapiPlugin(require('./package.json'));
plugin.vhost = 'my-vhost.example.com';
console.log(plugin.vhost); // 'my-vhost.example.com'
console.log(plugin.routes); // { vhost: 'my-vhost.example.com' }
module.exports = plugin.exports;
Exporting the plugin is one of the most important steps to successfully register a plugin to Hapi. It may be cumbersome to get right, so HapiPlugin takes care of the differences in syntax you can have in case there are routes or options involved.
If there is a need/desire to modify the collected configuration, it is stored in the config
(readonly) property. Read-only in this case prevent from overwriting the config
property entirely, but as objects are by reference in javascript, it will allow for direct manipulation, even though we don't particularly encourage this approach.
Please see Changelog
$ npm test
Please see Contributing
The MIT License (MIT). Please see License File for more information.
FAQs
Hapi plugin wrapper
We found that @magneds/hapi-plugin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.