https://github.com/alexkander/loopback-visible-properties-mixin
Loopback mixin hidden all models properties and allow setup what should be visibles.
https://github.com/alexkander/loopback-visible-properties-mixin
loopback mixin security strongloop website
Last synced: about 1 year ago
JSON representation
Loopback mixin hidden all models properties and allow setup what should be visibles.
- Host: GitHub
- URL: https://github.com/alexkander/loopback-visible-properties-mixin
- Owner: alexkander
- License: mit
- Created: 2018-02-03T04:02:31.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-01-23T18:36:15.000Z (over 3 years ago)
- Last Synced: 2025-03-08T19:15:36.811Z (over 1 year ago)
- Topics: loopback, mixin, security, strongloop, website
- Language: JavaScript
- Homepage:
- Size: 730 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
loopback-visible-properties-mixin
===============
[](https://badge.fury.io/js/loopback-visible-properties-mixin) [](https://travis-ci.org/arondn2/loopback-visible-properties-mixin)
[](https://coveralls.io/github/arondn2/loopback-visible-properties-mixin?branch=master)
Loopback mixin hidden all models properties and allow setup what should be visibles.
## Installation
`npm install loopback-visible-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-visible-properties-mixin",
"../common/mixins"
]
}
}
```
Add mixin params in in model definition. Example:
```
{
"name": "Person",
"properties": {
"firstName": "string",
"lastName": "string",
"email": "string",
},
"relaions": {
"siblings": {
"type": "referencesMany",
"model": "Person",
"foreignKey": "siblingsIds"
},
"mother": {
"type": "belongsTo",
"model": "Person",
"foreignKey": ""
},
"father": {
"type": "belongsTo",
"model": "Person",
"foreignKey": ""
},
"couple": {
"type": "belongsTo",
"model": "Person",
"foreignKey": ""
},
"children": {
"type": "hasMany",
"model": "Person",
foreignKey: "motherId"
},
},
"mixins": {
"VisibleProperties": {
"fields": {
"firstName": true,
"lastName": true,
"email": false,
"mother": true,
"motherId": false,
"father": true,
"fatherId": false,
"siblings": true,
"siblingsIds": false,
"children": true
}
}
}
}
```
You can setup this mixin with a array of visible properties too. Example:
```
{
"name": "Person",
...
"mixins": {
"VisibleProperties": {
"fields": [
"firstName",
"lastName",
"mother",
"father",
"siblings",
"children",
]
}
}
}
```
In the above definitions, the attributes `id`, `couple` and `coupleId` will not be visible in remote responses because they were ignored and `email`, `motherId`, `fatherId` and `siblingsIds` will not be visible because they were set `false`.
## 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-visible-properties-mixin/issues
Also, you can report the orthographic errors in the READMEs files or comments. Sorry for that, I do not speak English.
## Tests
`npm test` or `npm run cover`