https://github.com/alexkander/loopback-allowed-properties-mixin
Loopback mixin to set what fields can be received in request.
https://github.com/alexkander/loopback-allowed-properties-mixin
loopback mixin security strongloop web
Last synced: 12 months ago
JSON representation
Loopback mixin to set what fields can be received in request.
- Host: GitHub
- URL: https://github.com/alexkander/loopback-allowed-properties-mixin
- Owner: alexkander
- License: mit
- Created: 2018-02-01T01:14:56.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-01-23T18:35:57.000Z (about 3 years ago)
- Last Synced: 2025-03-23T01:35:59.526Z (12 months ago)
- Topics: loopback, mixin, security, strongloop, web
- Language: JavaScript
- Homepage:
- Size: 762 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
loopback-allowed-properties-mixin
===============
[](https://badge.fury.io/js/loopback-allowed-properties-mixin) [](https://travis-ci.org/arondn2/loopback-allowed-properties-mixin)
[](https://coveralls.io/github/arondn2/loopback-allowed-properties-mixin?branch=master)
Loopback mixin to set what fields can be written in a request.
## Installation
`npm install loopback-allowed-properties-mixin --save`
## Usage
Add the mixins property to your `server/model-config.json`:
```json
{
"_meta": {
"sources": [
"loopback/common/models",
"loopback/server/models",
"../common/models",
"./models"
],
"mixins": [
"loopback/common/mixins",
"../node_modules/loopback-allowed-properties-mixin",
"../common/mixins"
]
}
}
```
Add mixin params in model definition. Example:
```
{
"name": "Person",
"properties": {
"name": "string",
"email": "string",
"status": "string",
},
"mixins": {
"AllowedProperties": {
"create": [
"name",
"email"
],
"prototype.patchAttributes": [
"name"
],
"setStatus": [
"status"
]
}
}
}
```
In the above definition, `create` method will only recieve the request body with properties `name` and `email`, `prototype.patchAttributes` method will only recieve the request body with `name` attribute and finally `setStatus` method will only recieve `status` attribute in the body request.
## Troubles
If you have any kind of trouble with it, just let me now by raising an issue on the GitHub issue tracker here:
https://github.com/arondn2/loopback-allowed-properties-mixin/issues
Also, you can report the orthographic errors in the READMEs files or comments. Sorry for that, English is not my main language.
## Tests
`npm test` or `npm run cover`