Skip to content

Commit

Permalink
Merge pull request #23 from domapic/release-1.0.0-alpha.3
Browse files Browse the repository at this point in the history
Release 1.0.0 alpha.3
  • Loading branch information
javierbrea authored Dec 1, 2018
2 parents 6042e48 + d3bddab commit bc3f1cc
Show file tree
Hide file tree
Showing 35 changed files with 1,410 additions and 170 deletions.
49 changes: 46 additions & 3 deletions .narval.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ schemas:
bind: &bind
- lib
- test
- cli
- index.js
coverage: &disable-coverage
enabled: false
Expand Down Expand Up @@ -183,6 +182,7 @@ suites:
specs:
- test/functional/specs/no-controller-api-key.specs.js
- test/functional/specs/not-connected.specs.js
- test/functional/specs/storage.specs.js
coverage: *disable-coverage
- name: auth-api
describe: should add or remove api keys
Expand Down Expand Up @@ -271,6 +271,27 @@ suites:
specs:
- test/functional/specs/wrong-ability.specs.js
coverage: *disable-coverage
- name: wrong-ability-no-data
describe: should throw an error when trying to register an ability with state and no data
before: *clean
services:
- name: domapic-service
abort-on-error: true
local:
<<: *local-service-auth
env:
<<: *local-service-auth-env
fixture: wrong-ability-no-data
docker:
<<: *docker-service-auth
env:
<<: *docker-service-auth-env
fixture: wrong-ability-no-data
test:
<<: *functional-test
specs:
- test/functional/specs/wrong-ability-no-data.specs.js
coverage: *disable-coverage
- name: ability-data-types
describe: should work as expected and validate data for each type of ability data
before: *clean
Expand All @@ -295,6 +316,28 @@ suites:
- test/functional/specs/ability-string-enum.specs.js
- test/functional/specs/ability-number.specs.js
- test/functional/specs/ability-number-enum.specs.js
- test/functional/specs/ability-no-data.specs.js
coverage: *disable-coverage
- name: ability-wrong-responses
describe: should validate handler responses for each type of ability data
before: *clean
services:
- name: domapic-service
abort-on-error: true
local:
<<: *local-service-auth
env:
<<: *local-service-auth-env
fixture: abilities-wrong-responses
docker:
<<: *docker-service-auth
env:
<<: *docker-service-auth-env
fixture: abilities-wrong-responses
test:
<<: *functional-test
specs:
- test/functional/specs/ability-wrong-responses.specs.js
coverage: *disable-coverage
- name: documentation-example
describe: documentation example should work as expected
Expand All @@ -308,14 +351,14 @@ suites:
env: &documentation-example-local-env
<<: *local-service-auth-env
fixture: example
service_extra_options: --authDisabled --initialStatus=true
service_extra_options: --authDisabled --initialStatus=true --controllerApiKey=foo
docker:
<<: *docker-service-auth
command: test/functional/commands/start-service-no-name.sh
env: &documentation-example-docker-env
<<: *docker-service-auth-env
fixture: example
service_extra_options: --authDisabled --initialStatus=true
service_extra_options: --authDisabled --initialStatus=true --controllerApiKey=foo
test: &documentation-example-test
<<: *functional-test
local:
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed
### Removed

## [1.0.0-alpha.3] - 2018-12-01
### Added
- Expose storage method to services

### Changed
- Upgrade domapic-base version, which fixes a problem in Client concurrent requests.
- Do not demand data in abilities. Still mandatory in abilities with state defined.

### Fixed
- Extend exposed cli options with service options

## [1.0.0-alpha.2] - 2018-11-20
### BREAKING CHANGES
- Changed Controller uris to adapt them to Controller version 1.0.0-alpha.9
Expand Down
32 changes: 19 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ This package provides you all the API infrastructure, authentication, data valid

If you are going to __publish your module, add the `domapic-module` suffix to the name__, in order to allow npm users finding it easily searching in the website that keyword.

__NOTE: The next schema includes some Domapic pieces that are still not released. The web ui for the Controller, Domapic Cloud, mobile apps, as well as Homekit and Alexa plugins will be available soon.__

![Domapic system example][domapic-example-image]

> Above, an example of two modules in a [Domapic System][website-url]. Now, the relay can be controlled using the web or mobile applications, or interacting with ["Alexa"][alexa-url] or ["HomeKit"][homekit-url]. Automatisms can be configured in the [Domapic Controller Web UI][domapic-controller-url] to make the [_Phillips Hue_][hue-url] bulb be switched off automatically when the relay bulb is switched on, for example.
Expand All @@ -55,11 +57,11 @@ Modules can be created with few lines of code. Here is an example of a module co
```json
{
"name": "relay-domapic-module",
"name": "example-domapic-module",
"version": "1.0.0",
"description": "Domapic module controlling a relay",
"dependencies": {
"domapic-service": "1.0.0-alpha.2"
"domapic-service": "1.0.0-alpha.3"
}
}
```
Expand All @@ -70,10 +72,10 @@ const path = require('path')
const domapic = require('domapic-service')

domapic.createModule({ packagePath: path.resolve(__dirname) })
.then(async module => {
.then(async dmpcModule => {
let status = false

await module.register({
await dmpcModule.register({
switch: {
description: 'Handle the relay status',
data: {
Expand All @@ -90,14 +92,14 @@ domapic.createModule({ packagePath: path.resolve(__dirname) })
description: 'Switch on/off the relay',
handler: newStatus => {
status = newStatus
module.events.emit('switch', status)
dmpcModule.events.emit('switch', status)
return Promise.resolve(status)
}
}
}
})

return module.start()
return dmpcModule.start()
})
```
> When started, a REST api will be available to connect with controller, authenticate using api key, dispatch the switch action, consulting the switch state, the module configuration, etc.
Expand All @@ -116,6 +118,9 @@ Returns a module instance, containing:
* `config` `<object>` containing methods for getting and setting configuration.
* `get([key])` - Returns a promise resolved with the module configuration. Resolved with specific property value if argument `key` is provided.
* `set(key [, value])` - Sets `value` for provided `key` into module configuration. Returns a promise.
* `storage` `<object>` containing methods for getting and setting data in the built-in file system storage.
* `get([key])` - Returns a promise resolved with the module storage. Resolved with specific property value if argument `key` is provided.
* `set(key [, value])` - Sets `value` for provided `key` into module storage. Returns a promise.
* `api` - Object containing methods for [extending the built-in api](#extending-api).
* `register(abilitiesData)` - Register provided abilities into the module. Read the [abilities](#abilities) chapter for further info.
* `start` - Starts the server.
Expand All @@ -132,7 +137,7 @@ Each Module can has many abilities, each one with its own action, state and even
Each ability must be an object, which key will be the name of the ability (will be converted to snake case when referenced in api uris). Properties of each ability must be:

* `description` `<string>` Description of the ability.
* `data` `<object>` Defines the type of data that the ability will handle, and will be used to execute data validation for the action, state and event related api resources.
* `data` `<object>` Defines the type of data that the ability will handle, and will be used to execute data validation for the action, state and event related api resources. If the ability don't needs any type of data, this property should be omitted (in that case, the ability can't have an state, because it has no sense).
* `type` `<string>` Type of data. Can be one of `string`, `boolean`, `number`, `integer` or `float`
* `enum` `<array>` Used to restrict data to a fixed set of values. It must be an array with at least one element, where each element is unique.
* `minLength` `<number>` Minimum length of the data string.
Expand All @@ -157,7 +162,7 @@ Each ability must be an object, which key will be the name of the ability (will

#### Action

When an [ability](#abilities) has an `action` property defined, an api resource will be created with the uri `/api/[ability_key]/action`. It has to be requested using `POST` method, and data has to be provided in the request body, contained in the "data" property:
When an [ability](#abilities) has an `action` property defined, an api resource will be created with the uri `/api/[ability_key]/action`. It has to be requested using `POST` method, and data (if needed) has to be provided in the request body, contained in the "data" property:

> Example: http://localhost:3000/api/switch/action
```json
Expand Down Expand Up @@ -319,7 +324,7 @@ Consult the Controller Swagger interface to get more info about supported filter
First of all, remember to start the server programatically after adding the abilities in your code:

```js
module.start()
dmpcModule.start()
```

Once the module code is ready, the server can be started calling directly to the `npm start` command
Expand Down Expand Up @@ -418,6 +423,7 @@ npm start -- --help
* `logLevel` - Tracing level. Choices are 'log', 'trace', 'debug', 'info', 'warn' and 'error'. Default is `info`.
* `path` - Path to be used as home path for the process, instead of user´s default (a `.domapic` folder will be created inside).
* `saveConfig` - Save current options for next execution (except `name` and `path`). Default is false.
* `rejectUntrusted` - Reject untrusted ssl certificates when making requests to modules or plugins. Use it if you are using a self-signed certificate in your Controller. Default is false.

> Example of defining options from command line:
Expand Down Expand Up @@ -455,8 +461,8 @@ const options = require('./options')
domapic.createModule({
packagePath: path.resolve(__dirname),
customConfig: options
}).then(async module => {
let status = await module.config.get('initialStatus')
}).then(async dmpcModule => {
let status = await dmpcModule.config.get('initialStatus')
//...
})
```
Expand Down Expand Up @@ -523,9 +529,9 @@ npm run relay logs -- --lines=300

This command will display last logs of server, and will continue displaying logs until CTRL-C is pressed.

Server logs are managed by [PM2][pm2-url] when using CLI, so, it is recommended to install [_PM2 log rotate_][pm2-log-rotate-url] to avoid pm2 logs file growing too much.
Service process and logs are managed by [PM2][pm2-url] when using CLI, so, it is recommended to install [_PM2 log rotate_][pm2-log-rotate-url] to avoid pm2 logs file growing too much.

Server logs are saved too into a daily file. These files are rotated automatically and only last ten days files are kept. You´ll find these files in the `~/.domapic/[module-name]/logs` folder.
Service logs are saved too into a daily file. These files are rotated automatically and only last ten days files are kept. You´ll find these files in the `~/.domapic/[module-name]/logs` folder.


[domapic-logo-image]: http://domapic.com/assets/domapic-logo.png
Expand Down
11 changes: 0 additions & 11 deletions cli/index.js

This file was deleted.

4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ const ServiceCreator = function (Builder, type) {
const createModule = new ServiceCreator(serviceHandlers.Module, SERVICE_TYPES.MODULE)
const createPlugin = new ServiceCreator(serviceHandlers.Plugin, SERVICE_TYPES.PLUGIN)

const cli = cliOptions => domapic.cli(options.extendWith(cliOptions))

module.exports = {
createModule,
createPlugin,
cli: domapic.cli
cli
}
Loading

0 comments on commit bc3f1cc

Please sign in to comment.