
Security News
PodRocket Podcast: Inside the Recent npm Supply Chain Attacks
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
d-pac.plugins-spec
Advanced tools
This module formally defines the plugins specification for d-pac. It uses json-schema to describe the mandatory plugin declaration and the data it accepts.
A d-pac plugin must declare an object in its package.json
which adheres to schemas/pluginmanifest.json
To verify your plugin fullfils all requirements:
var spec = require('d-pac.plugins-spec');
var pkg = require('./package.json'); // retrieve your plugin's package manifest
var result = spec.validatePluginmanifest(pkg);
console.log(result.isValid);
A d-pac plugin must expose a method conform to its type
declaration in the manifest. ATM a single type is accepted: select
.
Example:
module.exports.select = function select(selectionpayload){
//do your stuff
};
This method should accept exactly one parameter which adheres to schemas/selectionpayload.json A plugin is allowed to override the payload schema in case it requires/ignores any of the fields.
References:
This module exposes a mapping of schema declarations to schema names as schemas
:
var spec = require('d-pac.plugins-spec');
console.log(Object.keys(spec.schemas));
#output
[ 'pluginmanifest',
'assessment',
'comparison',
'representation',
'selectionpayload' ]
It also exposes validators for each of the schemas:
console.log(Object.keys(spec));
#output
[ 'validatePluginmanifest',
'validateAssessment',
'validateComparison',
'validateRepresentation',
'validateSelectionpayload',
'schemas',
'createValidator',
'VERSION' ]
Usage:
validate<SchemaType>(data) : Object
var result = spec.validateComparison(comparison);
The result is an object with isValid: Boolean
and in case the data's not valid an errors
array with all errors.
You can create validators of your own, either based on one of the d-pac schemas, or completely new.
//new schema
var validator = subject.createValidator( {
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Test createValidator",
"type": "object",
"properties": {
"foo": {
"type": "number",
"required": true
}
}
} );
console.log(validator( { foo: "foo" } ).isValid); //outputs: false
console.log(validator( { foo: 9 } ).isValid); //outputs: true
//based on existing
var validator = subject.createValidator( "selectionpayload", {
"selectionpayload": {
"properties": {
"assessment": {
"required": true
}
}
},
"comparison": {
"properties": {
"updatedAt": {
"required": true
}
}
}
} );
The above example creates a validator based on schemas/selectionpayload.json by passing the "selectionpayload"
as a first argument.
You can override the rules of the original schema, by passing extra rules as objects mapped to the schema names.
E.g. the assessment
property of selectionpayload
is made mandatory in the above example.
Since the selectionpayload
schema references several other schemas, you can override these too. E.g. all comparison objects passed to selectionpayload.comparisons
are required to have a updatedAt
property.
The structure of the overriding object must be exactly the same as that of the base schema, i.e. make sure you adhere to it strictly.
You can use getPlugins
to retrieve plugin declarations from package manifests:
var plugins = subject.getPlugins({
"d-pac": [
{
"name": "test",
"description": "test",
"type": "select"
}
],
dependencies: {
'd-pac.plugins-spec': '^0.4.0'
}
});
To allow backwards compatibility to plugins that do not declare a dependency on this module, pass an options object with allowIndependents:true
:
var plugins = subject.getPlugins({
"d-pac": [
{
"name": "test",
"description": "test",
"type": "select"
}
]
}, {
allowIndependents: true
);
FAQs
D-pac plugin specification
We found that d-pac.plugins-spec 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.
Security News
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.