Gathering detailed insights and metrics for validata-koa
Gathering detailed insights and metrics for validata-koa
Gathering detailed insights and metrics for validata-koa
Gathering detailed insights and metrics for validata-koa
npm install validata-koa
Typescript
Module System
Node Version
NPM Version
TypeScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
1 Stars
111 Commits
2 Forks
1 Watchers
6 Branches
3 Contributors
Updated on Oct 24, 2024
Latest Version
5.0.2
Package Id
validata-koa@5.0.2
Unpacked Size
108.33 kB
Size
19.79 kB
File Count
52
NPM Version
6.14.18
Node Version
14.21.3
Published on
Oct 24, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
5
22
Type safe data validation and sanitization for Koa requests (body, query, headers, params) using validata.
See validata for more details on validation functionality.
1npm i validata validata-koa
1import * as Router from '@koa/router'; 2import * as Koa from 'koa'; 3import { Context } from 'koa'; 4import * as bodyParser from 'koa-bodyparser'; 5import { asNumber, isObject, isString, maybeString } from 'validata'; 6import validator from 'validator'; 7import { body, Statuses, validate } from 'validata-koa'; 8 9interface Body { 10 age: number; 11 email?: string; 12 name: string; 13} 14 15const bodyCheck = isObject<Body>({ 16 age: asNumber({ min: 0, coerceMax: 120 }), 17 email: maybeString({ validator: validator.isEmail }), 18 name: isString(), 19}); 20 21const app = new Koa(); 22app.use(bodyParser()); 23 24const router: Router = new Router(); 25// validate() middleware captures and formats validation issue responses 26router.post('/:id', validate(), (ctx: Context) => { 27 // these are now strongly typed 28 // if age is passed in as a string, it will be converted to a number (by the asNumber() check) 29 const { age, email, name } = body(ctx, bodyCheck); 30 console.log({ age, email, name }); 31 ctx.status = Statuses.OK; 32}); 33app.use(router.routes()); 34app.use(router.allowedMethods()); 35 36app.listen(8081);
1import * as Router from '@koa/router'; 2import * as Koa from 'koa'; 3import { Context } from 'koa'; 4import { asNumber, isObject, isString, maybeAsNumber } from 'validata'; 5import { params, query, Statuses, validate } from 'validata-koa'; 6 7interface Params { 8 id: number; 9} 10 11const paramsCheck = isObject<Params>({ 12 id: asNumber({ min: 0 }), 13}); 14 15interface Query { 16 filter: string; 17 page?: number; 18} 19 20const queryCheck = isObject<Query>({ 21 filter: isString(), 22 page: maybeAsNumber({ min: 0 }), 23}); 24 25const app = new Koa(); 26const router: Router = new Router(); 27 28// validate() middleware captures and formats validation issue responses 29router.post('/:id', validate(), (ctx: Context) => { 30 // these are now strongly typed 31 const { id } = params(ctx, paramsCheck); 32 const { filter, page } = query(ctx, queryCheck); 33 34 ctx.body = { id, filter, page }; 35 ctx.status = Statuses.OK; 36}); 37app.use(router.routes()); 38app.use(router.allowedMethods()); 39 40app.listen(8081);
Testing it out...
1curl -X POST localhost:8081/foo 2# status=400 3# {"issues":[{"path":[":","id"],"value":"foo","reason":"no-conversion","info":{"toType":"number"}}]} 4 5curl -X POST localhost:8081/12 6# status=400 7# {"issues":[{"path":["?","filter"],"reason":"not-defined"}]} 8 9curl -X POST localhost:8081/12?filter=test 10# status=200 11# {"id":12,"filter":"test"} 12 13curl -X POST localhost:8081/-2?filter=test 14# status=400 15# {"issues":[{"path":[":","id"],"value":-2,"reason":"min","info":{"min":0}}]}
... can be done in pretty much the same way
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
Found 1/15 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
15 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-14
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More