# node-cocona-net

> A basic microservices module based on Cherry and cote.

Latest version **0.1.1** (published 2017-12-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-cocona-net
pnpm add node-cocona-net
yarn add node-cocona-net
bun add node-cocona-net
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2017-12-06 |
| First published | 2017-11-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | pneugebala |
| Maintainers | pneugebala |

## Links

- npm: https://www.npmjs.com/package/node-cocona-net
- Repository: https://github.com/pneugebala/cocona-net
- npm.io page: https://npm.io/package/node-cocona-net

## Dependencies (5)

- [cote](https://npm.io/package/cote.md) ^0.15.1
- [semver](https://npm.io/package/semver.md) ^5.4.1
- [jsonfile](https://npm.io/package/jsonfile.md) ^4.0.0
- [node-cherry](https://npm.io/package/node-cherry.md) >=0.0.7
- [node-cherry-logger](https://npm.io/package/node-cherry-logger.md) *

## Recent versions

- 0.1.1 (latest) — 2017-12-06
- 0.1.0 — 2017-12-05
- 0.0.7 — 2017-11-17
- 0.0.6 — 2017-11-17

## README

# cocona-net

A basic microservices module based on [Cherry](https://github.com/pneugebala/Cherry) and [cote](https://github.com/dashersw/cote).

---

### Features:
* Scopes
* IDs
* Groups
* Versions
* Update triggers
* Encrypted data transfer

---

### Installation:
To install the module:
```
yarn add node-cocona-net
```
[Cherry](https://github.com/pneugebala/Cherry) is required to use cocona-net.
You can get started with a new [Cherry](https://github.com/pneugebala/Cherry) project by using [Cherry-CLI](https://github.com/pneugebala/Cherry-CLI).

---

### Configuration:

```javascript
await cherry.registerModule("node-cocona-net")
await cherry.createModule("node-cocona-net")
await cherry.loadModule("node-cocona-net", {
    loggingEnabled: true,
    conf: {
        id: "2qm7f4", //Default: name of current microservice package.json
        version: "0.0.1", //Default: version of current microservice package.json
        scope: "main", //Required: Scope of the used network
        key: "htpm5ezst5m5itj6", //Required: Encryption/Decryption key
        autoUpdate: true, //Default: true, should only be changed if really needed
    }
})
```

---

### Documentation:

* async **createResponder**
```javascript
let module = await cherry.getModule("node-cocona-net")
let result = await module.createResponder(name, id = false, group = false, ignoreVersion = false)
```
Creates a new cote responder with given name, id and group. Only responder/requester with the same id and group can communicate with each other (Defaults to service id). Can ignore versions in the network (Only scope and group used). Returns **true** if successful.

---

* async **onResponder**
```javascript
let module = await cherry.getModule("node-cocona-net")
let result = await module.onResponder(name, event, func)

Example:
let result = await module.onResponder("TestResponder", "test", (data, cb) => {
    if(data.test === true)
        cb(true)
    else
        cb(false)
})
```
Creates a new cote responder event handler with given name and event type. Func gets called on every event with data and callback to send result back. Returns **true** if successful.

---

* async **createRequester**
```javascript
let module = await cherry.getModule("node-cocona-net")
let result = await module.createRequester(name, id = false, group = false, ignoreVersion = false)
```
Creates a new cote requester with given name, id and group. Only responder/requester with the same id and group can communicate with each other (Defaults to service id). Can ignore versions in the network (Only scope and group used). Returns **true** if successful.

---

* async **sendRequest**
```javascript
let module = await cherry.getModule("node-cocona-net")
let result = await module.sendRequest(name, event, alive, data, cb)

Example:
let result = await module.sendRequest("TestRequester", "test", 5000, {test: true}, (data) => {
    console.log(data)
})
```
Sends a new cote request with given name, event type, timeout in milliseconds and data. Callback gets called with result. Returns **true** if successful.

---

* async **createPublisher**
```javascript
let module = await cherry.getModule("node-cocona-net")
let result = await module.createPublisher(name, id = false, group = false, ignoreVersion = false)
```
Creates a new cote publisher with given name, id and group. Only publisher/subscriber with the same id and group can communicate with each other (Defaults to service id). Can ignore versions in the network (Only scope and group used). Returns **true** if successful.

---

* async **sendBroadcast**
```javascript
let module = await cherry.getModule("node-cocona-net")
let result = await module.sendBroadcast(name, event, data)

Example:
let result = await module.sendBroadcast("TestPublisher", "test", {test: true})
```
Sends a new broadcast via cote publisher with given name, event type and data. Returns **true** if successful.

---

* async **createSubscriber**
```javascript
let module = await cherry.getModule("node-cocona-net")
let result = await module.createSubscriber(name, id = false, group = false, ignoreVersion = false)
```
Creates a new cote subscriber with given name, id and group. Only publisher/subscriber with the same id and group can communicate with each other (Defaults to service id). Can ignore versions in the network (Only scope and group used). Returns **true** if successful.

---

* async **onBroadcast**
```javascript
let module = await cherry.getModule("node-cocona-net")
let result = await module.onBroadcast(name, event, func)

Example:
let result = await module.onBroadcast("TestPublisher", "test", (data) => {
    console.log(data)
})
```
Creates a broadcast event handler via cote subsriver with given name and event type. Func gets called on every event with data. Returns **true** if successful.

---

* async **onUpdateEvent**
```javascript
let module = await cherry.getModule("node-cocona-net")
let result = await module.onUpdateEvent(func)

Example:
let result = await module.onUpdateEvent(() => {
    console.log("Update")
})
```
Creates an update event handler (Using service id; cocona-net updates are global). Func gets called on every update event. Returns **true** if successful.

---

* async **onIdle**
```javascript
let module = await cherry.getModule("node-cocona-net")
let result = await module.onIdle(func)

Example:
let result = await module.onIdle(() => {
    console.log("Idle")
})
```
Creates an idle event handler. Func gets called anytime the application is idle (No requests being processed). Returns **true** if successful.

---

### Contribution:
To run tests (incomplete):
```
yarn test
```
To start a test environment:
```
yarn start
```

---
_Source: https://npm.io/package/node-cocona-net · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
