Skip to content

Commit

Permalink
Merge pull request #42 from domapic/release-1.0.0-alpha.10
Browse files Browse the repository at this point in the history
Release 1.0.0 alpha.10
  • Loading branch information
javierbrea committed Nov 26, 2018
2 parents 8d33525 + 70060dc commit 0ffa5b6
Show file tree
Hide file tree
Showing 21 changed files with 674 additions and 90 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed
### Removed

## [1.0.0-alpha.10] - 2018-11-25
### Added
- Add express-mongo-sanitize middleware

### Changed
- Type property in abilities becomes not mandatory when ability has not state
- Data property is not allowed in ability handlers when ability type is not defined

## [1.0.0-alpha.9] - 2018-11-18
### Added
- Send entity operations events to all registered plugins
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![Build status][travisci-image]][travisci-url] [![Coverage Status][coveralls-image]][coveralls-url] [![Quality Gate][quality-gate-image]][quality-gate-url] [![js-standard-style][standard-image]][standard-url]

[![NPM dependencies][npm-dependencies-image]][npm-dependencies-url] [![Last commit][last-commit-image]][last-commit-url] [![Last release][release-image]][release-url]
[![NPM dependencies][npm-dependencies-image]][npm-dependencies-url] [![Last commit][last-commit-image]][last-commit-url] <!-- [![Last release][release-image]][release-url] -->

[![NPM downloads][npm-downloads-image]][npm-downloads-url] [![Website][website-image]][website-url] [![License][license-image]][license-url]

Expand Down Expand Up @@ -105,9 +105,10 @@ This command will stop the server, and, if you used the `--save` option when you
domapic-controller start
```

If you want your server to be started automatically on system reload, use the pm2 save command:
If you want your server to be started automatically on system reload, use the `pm2 startup` and `pm2 save` commands:

```bash
pm2 startup
pm2 save
```

Expand Down Expand Up @@ -142,6 +143,7 @@ option | description | default
`--logLevel` | Tracing level. Choices are 'log', 'trace', 'debug', 'info', 'warn' and 'error' | info
`--path` | Path to be used as home path, instead of user´s default (.domapic folder will be created inside) | ~
`--saveConfig` | Save current options for next execution (except `name` and `path`) | false
`--rejectUntrusted` | Reject untrusted ssl certificates when making requests to modules or plugins | false

Example of setting options from command line:
```shell
Expand Down
2 changes: 1 addition & 1 deletion lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const Client = service => {
return service.tracer.debug(templates.sendingAbilityAction({
_service: serviceData._id,
_ability: ability._id,
data: data.data
data: data.data || ''
})).then(() => client.post(uris.abilityActionHandler(ability.name), data)
.catch(handleServiceError)
)
Expand Down
6 changes: 2 additions & 4 deletions lib/api/abilities.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
"type": "string"
}
},
"required": ["_id", "name", "_service", "type"],
"required": ["_id", "name", "_service"],
"additionalProperties": false,
"example": {
"_id": "1223123",
Expand Down Expand Up @@ -241,7 +241,7 @@
"type": "boolean"
}
},
"required": ["name", "type"],
"required": ["name"],
"additionalProperties": false,
"example": {
"name": "foo-ability-name",
Expand Down Expand Up @@ -556,7 +556,6 @@
"operationId": "abilityAction",
"requestBody": {
"description": "Data of the action",
"required": true,
"content": {
"application/json": {
"schema": {
Expand Down Expand Up @@ -638,7 +637,6 @@
"operationId": "abilityEvent",
"requestBody": {
"description": "Data of the event",
"required": true,
"content": {
"application/json": {
"schema": {
Expand Down
6 changes: 6 additions & 0 deletions lib/commands/ability.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ const Commands = (service, models, client) => {
.then(ability => service.tracer.debug(templates.abilityRemoved(ability)))

const validateData = (ability, data) => {
if (ability.type && isUndefined(data.data)) {
return Promise.reject(new service.errors.BadData(templates.abilityDataRequired()))
}
if (!ability.type && !isUndefined(data.data)) {
return Promise.reject(new service.errors.BadData(templates.abilityDataNotAllowed()))
}
const dataSchema = omitBy(pick(ability, [
'type',
'format',
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/composed.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const Commands = (service, models, client, commands) => {
service.tracer.debug(templates.receivedAbilityEvent({
_service: serviceData._id,
_ability: ability._id,
data: data.data
data: data.data || ''
}))
])
}))
Expand Down
2 changes: 2 additions & 0 deletions lib/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const Promise = require('bluebird')
const path = require('path')

const domapic = require('domapic-base')
const mongoSanitize = require('express-mongo-sanitize')

const lib = require('./index')
const options = require('./options')
Expand All @@ -27,6 +28,7 @@ const initService = (service) => {
const extendOpenApis = () => Promise.map(api.openapis, openapi => service.server.extendOpenApi(openapi))

return database.connect()
.then(() => service.server.addMiddleware(mongoSanitize()))
.then(() => security.methods().then(methods => service.server.addAuthentication(methods)))
.then(() => extendOpenApis())
.then(() => service.server.addOperations(api.operations))
Expand Down
19 changes: 18 additions & 1 deletion lib/models/ability.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@ const Model = service => {
const Schema = mongoose.Schema
const models = {}

const requireTypeIfHasData = function () {
if (this.state ||
this.format ||
this.enum ||
this.maxLength ||
this.minLength ||
this.pattern ||
this.multipleOf ||
this.minimum ||
this.maximum ||
this.exclusiveMaximum ||
this.exclusiveMinimum) {
return true
}
return false
}

const schema = new Schema({
_service: {
type: String,
Expand Down Expand Up @@ -49,7 +66,7 @@ const Model = service => {
},
type: {
type: String,
required: [true, templates.abilityTypeRequired()],
required: [requireTypeIfHasData, templates.abilityTypeRequired()],
enum: ['string', 'number', 'float', 'integer', 'boolean']
},
format: {
Expand Down
2 changes: 2 additions & 0 deletions lib/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ const templates = {

abilityNameRequired: 'Ability name required',
abilityTypeRequired: 'Ability data type is required',
abilityDataRequired: 'Data is required',
abilityDataNotAllowed: 'Ability has not defined type. Data property is not allowed',
abilityNotFound: 'Ability not found',
abilityAdded: 'New ability with name "{{name}}" of service "{{_service}}" was added. Assigned id: "{{_id}}"',
abilityServiceRequired: 'Ability service is required',
Expand Down
Loading

0 comments on commit 0ffa5b6

Please sign in to comment.