# comaas

> COMmand As A Service, make command available as http service. Useful in micro services.

Latest version **0.3.3** (published 2018-07-01) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install comaas
pnpm add comaas
yarn add comaas
bun add comaas
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.3.3 |
| Published | 2018-07-01 |
| First published | 2018-06-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >= 8.11.1 |
| Dependencies | 1 |
| Unpacked size | 27.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Pressop |
| Maintainers | wedgesama |
| Keywords | microservice, service, shell, http, command |

## Links

- npm: https://www.npmjs.com/package/comaas
- Repository: https://gitlab.com/pressop/comaas
- npm.io page: https://npm.io/package/comaas

## Dependencies (1)

- [rxjs](https://npm.io/package/rxjs.md) ^5.5.11

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 0.3.3 (latest) — 2018-07-01
- 0.3.2 — 2018-06-24
- 0.3.1 — 2018-06-24
- 0.3.0 — 2018-06-24
- 0.2.0 — 2018-06-23
- 0.1.1 — 2018-06-22
- 0.1.0 — 2018-06-22

## README

COMmand As A Service
==================

Make command available as http service. Useful in micro services.

!!! Do not come with security system, you have to implement your own security layer. !!!

## Install
```bash
yarn add comaas
```

## An example with ls command (not relevant but easy to understand)

```typescript
import {
    createServer,
    ArgumentParser,
    Command,
    CommandContext,
    CommandRequest,
} from 'comaas';
import {ServerResponse} from 'http';
import {Observable} from 'rxjs/Observable';
import {Observer} from 'rxjs/Observer';

class Ls implements Command {
    getBin(): string {
        return '/bin/ls';
    }

    getPath(): string {
        return '/ls';
    }

    createContext(request: CommandRequest): Observable<CommandContext> {
        return Observable.create((observer: Observer<CommandContext>) => {
            const context = new CommandContext();

            context.cmd = this.getBin();
            context.args = ArgumentParser.normalize(request.args);

            observer.next(context);
            observer.complete();
        });
    }

    prepareResponse(response: ServerResponse): void {
        response.statusCode = 200;
        response.setHeader('Content-Type', 'text/plain');
    }
}

let server = createServer([
    new Ls(),
]);

server.listen(8156, '127.0.0.1', () => {
    console.log('Server started on http://127.0.0.1:8156');
});
```

Request

```
curl --request POST \
  --url http://127.0.0.1:8156/ls \
  --header 'content-type: application/json' \
  --data '{
    "args": [{
        "key": "/home/user"
    }]
}'
```
 
## Know issues
- Nothing (yet)

## TODO
- Unit tests.
- Implement whitelist for args.
- Implement an arg value validator.

## License

Release under MIT license.

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