Research
Security News
Malicious npm Package Typosquats react-login-page to Deploy Keylogger
Socket researchers unpack a typosquatting package with malicious code that logs keystrokes and exfiltrates sensitive data to a remote server.
cmbf-hapi-restmodel
Advanced tools
Readme
This HAPI plugin exposes helpers to easily create RESTful API from a model definition based on Joi schema.
It requires the use of other CMBF plugins. See CMBF-Core for more details
Install using npm:
npm install cmbf-hapi-restmodel --save
With the CMBF launcher, you just add a server hook to load additional plugins like this :
{'register-plugins': function(params, defaultImpl) {
"use strict";
var Cmbf = this;
Cmbf.log.debug("Registering specific plugins");
return defaultImpl().then(function() {
return P.join(
Cmbf.installPlugin(require('cmbf-hapi-restmodel'))
// Load other plugins...
);
});
}}
You just register this server hook by calling the registerHooks method:
Cmbf.registerHooks(require('./lib/server-hooks'));
The primary service to register models is called modelManager. Inside your plugin implementation, you retrieve a reference to it through the configured plugins:
var modelManager = server.plugins['cmbf-restmod'].modelManager;
This service exposes a registerModel
method that you call, providing a model definition.
modelManager.registerModel('banana', require('./models/bananas.js);
The model will create all required routes and mongodb collections for the following operations:
Ideally, you define your model using the new ES6 class concept:
var Joi = require('joi');
module.exports = function(server, config, log) {
"use strict";
var BaseModel = server.plugins['cmbf-hapi-restmodel'].BaseModel;
var clock = server.plugins['covistra-system'].clock;
class Document extends BaseModel {
static get endpoint() {
return "documents";
}
static get auth() {
return "token";
}
static get name() {
return "document";
}
static get collection() {
return 'documents';
}
static get Schema() {
return Joi.object().keys({
key: Joi.string().required(),
name: Joi.string().required(),
ownerId: Joi.string(),
customerId: Joi.string(),
type: Joi.string(),
tags: Joi.array().items(Joi.string()),
content: Joi.any(),
created_at: Joi.date().default(clock.nowTs, "Default to current time")
});
}
}
return Document;
};
You then register this model descriptor:
var Document = require('./models/document')(server, config, log);
modelManager.registerModel('document', Document`);
This model will get automatically exposed when the server stats with all standard routes generated for you.
Sometimes you need to override the field through which you model is referenced. By default,
we use a id
field, but you just have to override the idField property in your
derived model:
class MyModel extends BaseModel {
static get idField() {
return 'key';
}
}
FAQs
Unknown package
We found that cmbf-hapi-restmodel demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Research
Security News
Socket researchers unpack a typosquatting package with malicious code that logs keystrokes and exfiltrates sensitive data to a remote server.
Security News
The JavaScript community has launched the e18e initiative to improve ecosystem performance by cleaning up dependency trees, speeding up critical parts of the ecosystem, and documenting lighter alternatives to established tools.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.