q3-core-composer
Advanced tools
Comparing version 1.0.13 to 1.0.20
@@ -6,3 +6,6 @@ const connect = require('connect'); | ||
const effect = require('./lib/effect'); | ||
const validate = require('./lib/validate'); | ||
const { | ||
validateBody, | ||
validateIf, | ||
} = require('./lib/validate'); | ||
@@ -40,3 +43,3 @@ const { | ||
flatten([ | ||
flatten(ctr.validation, [validate]), | ||
flatten(ctr.validation, [validateBody]), | ||
flatten(ctr.authorization, [ | ||
@@ -58,2 +61,3 @@ verify, | ||
check, | ||
validateIf, | ||
}; |
@@ -16,2 +16,4 @@ const { get, set } = require('lodash'); | ||
// this needs refactoring | ||
// needs conditional? | ||
const redact = (modelName) => { | ||
@@ -76,4 +78,4 @@ const locations = { | ||
const verify = ({ user }, res, next) => { | ||
if (!user) { | ||
const verify = ({ user, passedGrants }, res, next) => { | ||
if (!user && !passedGrants) { | ||
res.status(401).send(); | ||
@@ -80,0 +82,0 @@ } else { |
const { | ||
matchedData, | ||
validationResult, | ||
checkSchema, | ||
} = require('express-validator'); | ||
@@ -9,3 +10,22 @@ const { pickBy } = require('lodash'); | ||
module.exports = (req, res, next) => { | ||
const validateIf = ( | ||
discriminatorKey = '__t', | ||
schemas = {}, | ||
) => async (req, res, next) => { | ||
const v = req.body[discriminatorKey]; | ||
const schema = schemas[v || 'base']; | ||
if (schema) { | ||
await Promise.all( | ||
checkSchema(schema).map((e) => e.run(req)), | ||
); | ||
next(); | ||
} else { | ||
next( | ||
new Error(req.t('messages:discriminatorRequired')), | ||
); | ||
} | ||
}; | ||
const validateBody = (req, res, next) => { | ||
try { | ||
@@ -23,1 +43,6 @@ validationResult(req).throw(); | ||
}; | ||
module.exports = { | ||
validateBody, | ||
validateIf, | ||
}; |
{ | ||
"name": "q3-core-composer", | ||
"version": "1.0.13", | ||
"version": "1.0.20", | ||
"main": "index.js", | ||
@@ -10,14 +10,15 @@ "jest": { | ||
"connect": "^3.7.0", | ||
"express": "^4.17.1", | ||
"express-async-handler": "^1.1.4", | ||
"express-mung": "^0.5.1", | ||
"express-validator": "^6.2.0", | ||
"flat": "^4.1.0", | ||
"flat": "5.0.0", | ||
"lodash": "^4.17.15", | ||
"micromatch": "^4.0.2" | ||
"micromatch": "^4.0.2", | ||
"mongoose": "^5.7.7" | ||
}, | ||
"devDependencies": { | ||
"express": "^4.17.1", | ||
"supertest": "^4.0.2" | ||
}, | ||
"gitHead": "824e526a638198a3d3ddbd7d077bdf676f876711" | ||
"gitHead": "0b3cd9783303e9853037b7bdacdaffbc549f4ad2" | ||
} |
@@ -1,2 +0,2 @@ | ||
const validate = require('../lib/validate'); | ||
const { validateBody } = require('../lib/validate'); | ||
@@ -14,3 +14,3 @@ const req = { body: {} }; | ||
req.body = null; | ||
validate(req, res, next); | ||
validateBody(req, res, next); | ||
expect(next).toHaveBeenCalledWith(expect.any(Object)); | ||
@@ -28,3 +28,3 @@ }); | ||
validate(req, res, next); | ||
validateBody(req, res, next); | ||
expect(req.body).not.toHaveProperty('dropNull'); | ||
@@ -31,0 +31,0 @@ expect(req.body).not.toHaveProperty('dropUndefined'); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1
650
15925
9
9
1
+ Addedexpress@^4.17.1
+ Addedmongoose@^5.7.7
+ Added@types/bson@4.0.5(transitive)
+ Added@types/mongodb@3.6.20(transitive)
+ Added@types/node@22.9.1(transitive)
+ Addedaccepts@1.3.8(transitive)
+ Addedarray-flatten@1.1.1(transitive)
+ Addedbl@2.2.1(transitive)
+ Addedbluebird@3.5.1(transitive)
+ Addedbody-parser@1.20.3(transitive)
+ Addedbson@1.1.6(transitive)
+ Addedbytes@3.1.2(transitive)
+ Addedcall-bind@1.0.7(transitive)
+ Addedcontent-disposition@0.5.4(transitive)
+ Addedcontent-type@1.0.5(transitive)
+ Addedcookie@0.7.1(transitive)
+ Addedcookie-signature@1.0.6(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addeddebug@3.1.0(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddenque@1.5.1(transitive)
+ Addeddepd@2.0.0(transitive)
+ Addeddestroy@1.2.0(transitive)
+ Addedencodeurl@2.0.0(transitive)
+ Addedes-define-property@1.0.0(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedetag@1.8.1(transitive)
+ Addedexpress@4.21.1(transitive)
+ Addedfinalhandler@1.3.1(transitive)
+ Addedflat@5.0.0(transitive)
+ Addedforwarded@0.2.0(transitive)
+ Addedfresh@0.5.2(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedgopd@1.0.1(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhttp-errors@2.0.0(transitive)
+ Addediconv-lite@0.4.24(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedipaddr.js@1.9.1(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedkareem@2.3.2(transitive)
+ Addedmedia-typer@0.3.0(transitive)
+ Addedmemory-pager@1.5.0(transitive)
+ Addedmerge-descriptors@1.0.3(transitive)
+ Addedmethods@1.1.2(transitive)
+ Addedmime@1.6.0(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedmongodb@3.7.4(transitive)
+ Addedmongoose@5.13.22(transitive)
+ Addedmongoose-legacy-pluralize@1.0.2(transitive)
+ Addedmpath@0.8.4(transitive)
+ Addedmquery@3.2.5(transitive)
+ Addedms@2.1.22.1.3(transitive)
+ Addednegotiator@0.6.3(transitive)
+ Addedobject-inspect@1.13.3(transitive)
+ Addedon-finished@2.4.1(transitive)
+ Addedoptional-require@1.0.31.1.8(transitive)
+ Addedpath-to-regexp@0.1.10(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedproxy-addr@2.0.7(transitive)
+ Addedqs@6.13.0(transitive)
+ Addedrange-parser@1.2.1(transitive)
+ Addedraw-body@2.5.2(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedregexp-clone@1.0.0(transitive)
+ Addedrequire-at@1.0.6(transitive)
+ Addedsafe-buffer@5.1.25.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsaslprep@1.0.3(transitive)
+ Addedsend@0.19.0(transitive)
+ Addedserve-static@1.16.2(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedsetprototypeof@1.2.0(transitive)
+ Addedside-channel@1.0.6(transitive)
+ Addedsift@13.5.2(transitive)
+ Addedsliced@1.0.1(transitive)
+ Addedsparse-bitfield@3.0.3(transitive)
+ Addedstatuses@2.0.1(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedtoidentifier@1.0.1(transitive)
+ Addedtype-is@1.6.18(transitive)
+ Addedundici-types@6.19.8(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedvary@1.1.2(transitive)
- Removedflat@4.1.1(transitive)
Updatedflat@5.0.0