
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
koa-scheme
Advanced tools
koa-scheme is a parameter validation middleware for koa.
version v3.0.0 support for koa2
npm i koa-scheme --save
scheme(config, options)
config and throw error, Default false.app.js
var koa = require('koa');
//var bodyParser = require('koa-bodyparser');
var scheme = require('koa-scheme');
var conf = require('./scheme');
var route = require('./route');
var app = koa();
//app.use(bodyParser());
app.use(scheme(conf));
route(app);
app.listen(3000, function() {
console.log("listening on 3000")
});
scheme.json
{
"/(.*)": {
"request": {
"header": {
"version": "[1-9]+"
}
}
},
"/": {
"response": {
"status": 200
}
},
"GET /user/:username": {
"response": {
"body": {
"name": /[a-z]+/i,
"age": "[0-9]{1,3}"
}
}
},
"/user/:username": {
"request": {
"method": "(POST|patch)",
"body": {
"name": "[a-zA-Z]+",
"age": /[0-9]{1,3}/
}
},
"response": {
"status": 200
}
},
"(delete|OPTIONS) /user/:username": {
...
}
}
see path-to-regexp.
NB: when use body-parser middleware (like: koa-bodyparser) before koa-scheme, you could configure 'body' field in 'request'.
use function:
scheme.js
module.exports = {
"/users": {
"request": {
"method": "POST",
"body": {
"nameArr": testRequestNameArr
}
}
}
}
function testRequestNameArr(arr) {
if (arr.length === 3 && arr[1] === 'nswbmw') {
return true;
} else {
return false;
}
}
with validator:
scheme.js
var validator = require('validator');
module.exports = {
"GET /user/:username": {
"response": {
"body": {
"age": validator.isNumeric,
"email": validator.isEmail,
"webset": validator.isURL,
...
}
}
}
}
Even you could write flat object like this:
{
"GET /user/:username": {
"response": {
"body.age": validator.isNumeric,
"body.email": validator.isEmail,
"body.family.mother.age": validator.isNumeric
}
}
}
scheme.js
var validator = require('validator');
module.exports = {
"/(.*)": {
"request": {
"header.version": "[1-9]+"
}
},
"/users": {
"request": {
"method": "GET"
},
"response": {
"body": testRes
}
},
"GET /user/:username": {
"response": {
"body": {
"name": "[a-zA-Z]+",
"age": validator.isNumeric,
"email": validator.isEmail
}
}
},
"/user/:username": {
"request": {
"method": "(POST|PATCH)",
"body.name": /[a-zA-Z]+/,
"body.age": "[0-9]{1,3}",
"body.email": validator.isEmail
}
},
"(delete|OPTIONS) /user/:username": {
"response": {
"status": 200
}
}
}
// throw a error is ok
function testRes(arr) {
throw new Error('badRequest');
}
npm test
MIT
FAQs
koa-scheme is a parameter validation middleware for koa.
The npm package koa-scheme receives a total of 12 weekly downloads. As such, koa-scheme popularity was classified as not popular.
We found that koa-scheme 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
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.