├── .gitignore ├── LICENSE ├── README.md ├── example ├── .editorconfig ├── .gitignore ├── .jshintrc ├── .npmignore ├── LICENSE ├── README.md ├── config │ ├── default.json │ └── production.json ├── package.json ├── public │ ├── favicon.ico │ └── index.html ├── src │ ├── app.js │ ├── hooks │ │ └── index.js │ ├── index.js │ ├── middleware │ │ ├── index.js │ │ ├── logger.js │ │ └── not-found-handler.js │ └── services │ │ ├── index.js │ │ └── message │ │ ├── hooks │ │ └── index.js │ │ └── index.js └── test │ ├── app.test.js │ └── services │ └── message │ └── index.test.js ├── lib └── validate │ └── index.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log 3 | _src 4 | _tests -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | ## MIT License 2 | 3 | Copyright (C) 2016 [Feathers contributors](https://github.com/feathersjs/feathers/graphs/contributors) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## feathers-validate-hook 2 | 3 | [](https://nodei.co/npm/feathers-validate-hook/) 4 | 5 | [](https://www.npmjs.org/package/feathers-validate-hook) 6 | [](https://david-dm.org/kulakowka/feathers-validate-hook) 7 | 8 | 9 | This is experiment. **Work in progress!** 10 | 11 | Feathers hook for validate json-schema with [is-my-json-valid](https://www.npmjs.com/package/is-my-json-valid) 12 | 13 | ```javascript 14 | const validateHook = require('feathers-validate-hook') 15 | 16 | // Define schema 17 | const schema = { 18 | required: true, 19 | type: 'object', 20 | properties: { 21 | // Required attribute 'text' with type 'string' 22 | text: { 23 | required: true, 24 | type: 'string' 25 | } 26 | } 27 | } 28 | 29 | app.service('/messages').before({ 30 | create: [ 31 | validateHook(schema) 32 | ] 33 | }) 34 | ``` 35 | 36 | ## Example 37 | 38 | Look [example folder](https://github.com/kulakowka/feathers-validate-hook/tree/master/example) for more information. 39 | 40 | Test request: 41 | ``` 42 | curl -H "Accept: application/json" -X POST http://localhost:3030/messages 43 | ``` 44 | 45 | Server response example: 46 | ``` 47 | { 48 | "name": "BadRequest", 49 | "message": "Validation failed", 50 | "code": 400, 51 | "className": "bad-request", 52 | "data": {}, 53 | "errors": [ 54 | { 55 | "field": "data.text", 56 | "message": "is required", 57 | "type": "string" 58 | } 59 | ] 60 | } 61 | ``` 62 | -------------------------------------------------------------------------------- /example/.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # Compiled binary addons (http://nodejs.org/api/addons.html) 20 | build/Release 21 | 22 | # Dependency directory 23 | # Commenting this out is preferred by some people, see 24 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- 25 | node_modules 26 | 27 | # Users Environment Variables 28 | .lock-wscript 29 | 30 | lib/ 31 | data/ 32 | -------------------------------------------------------------------------------- /example/.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "node": true, 3 | "esnext": true, 4 | "bitwise": true, 5 | "camelcase": true, 6 | "curly": true, 7 | "eqeqeq": true, 8 | "immed": true, 9 | "indent": 2, 10 | "latedef": "nofunc", 11 | "newcap": false, 12 | "noarg": true, 13 | "quotmark": "single", 14 | "regexp": true, 15 | "undef": true, 16 | "unused": false, 17 | "strict": false, 18 | "trailing": true, 19 | "smarttabs": true, 20 | "white": false, 21 | "globals": { 22 | "it": true, 23 | "describe": true, 24 | "before": true, 25 | "beforeEach": true, 26 | "after": true, 27 | "afterEach": true 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /example/.npmignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # Compiled binary addons (http://nodejs.org/api/addons.html) 20 | build/Release 21 | 22 | # Dependency directory 23 | # Commenting this out is preferred by some people, see 24 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- 25 | node_modules 26 | 27 | # Users Environment Variables 28 | .lock-wscript 29 | 30 | data/ 31 | -------------------------------------------------------------------------------- /example/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Feathers 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # example 2 | 3 | ```bash 4 | git clone git@github.com:kulakowka/feathers-validate-hook.git 5 | cd feathers-validate-hook 6 | npm install 7 | cd example 8 | npm install 9 | npm start 10 | ``` 11 | 12 | Test request: 13 | ``` 14 | curl -H "Accept: application/json" -X POST http://localhost:3030/messages 15 | ``` 16 | 17 | Server response example: 18 | ``` 19 | { 20 | "name": "BadRequest", 21 | "message": "Validation failed", 22 | "code": 400, 23 | "className": "bad-request", 24 | "data": {}, 25 | "errors": [ 26 | { 27 | "field": "data.text", 28 | "message": "is required", 29 | "type": "string" 30 | } 31 | ] 32 | } 33 | ``` 34 | -------------------------------------------------------------------------------- /example/config/default.json: -------------------------------------------------------------------------------- 1 | { 2 | "host": "localhost", 3 | "port": 3030, 4 | "public": "../public/" 5 | } 6 | -------------------------------------------------------------------------------- /example/config/production.json: -------------------------------------------------------------------------------- 1 | { 2 | "host": "example-app.feathersjs.com", 3 | "port": 80, 4 | "public": "../public/" 5 | } 6 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example", 3 | "description": "", 4 | "version": "0.0.0", 5 | "homepage": "", 6 | "main": "src/", 7 | "keywords": [ 8 | "feathers" 9 | ], 10 | "license": "MIT", 11 | "repository": {}, 12 | "author": {}, 13 | "contributors": [], 14 | "bugs": {}, 15 | "engines": { 16 | "node": ">= 0.12.0" 17 | }, 18 | "scripts": { 19 | "start": "node --harmony --harmony_default_parameters src/", 20 | "jshint": "jshint src/. test/. --config", 21 | "mocha": "mocha test/ --recursive", 22 | "test": "npm run jshint && npm run mocha" 23 | }, 24 | "dependencies": { 25 | "body-parser": "^1.15.0", 26 | "compression": "^1.6.1", 27 | "cors": "^2.7.1", 28 | "feathers": "^2.0.0", 29 | "feathers-configuration": "^0.1.0", 30 | "feathers-errors": "^2.0.1", 31 | "feathers-hooks": "^1.0.0", 32 | "feathers-memory": "^0.6.3", 33 | "feathers-rest": "^1.0.0", 34 | "serve-favicon": "^2.3.0", 35 | "winston": "^2.2.0" 36 | }, 37 | "devDependencies": { 38 | "jshint": "^2.9.1", 39 | "mocha": "^2.4.5", 40 | "request": "^2.69.0" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /example/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kulakowka/feathers-validate-hook/4c31d3515c820a6fd4d225e7d2c55db974a55e0c/example/public/favicon.ico -------------------------------------------------------------------------------- /example/public/index.html: -------------------------------------------------------------------------------- 1 | 2 |
3 |