# comm-interface

> Communication interface

Latest version **1.7.7** (published 2020-04-27) · ISC license · 0 weekly downloads

## Install

```sh
npm install comm-interface
pnpm add comm-interface
yarn add comm-interface
bun add comm-interface
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.7.7 |
| Published | 2020-04-27 |
| First published | 2019-04-08 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 17 |
| Unpacked size | 53.6 KB |
| Known vulnerabilities | 0 (+10 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | vedadf |

## Links

- npm: https://www.npmjs.com/package/comm-interface
- Repository: https://github.com/dtk/comm-interface
- Homepage: https://github.com/dtk/comm-interface#readme
- Issues: https://github.com/dtk/comm-interface/issues
- npm.io page: https://npm.io/package/comm-interface

## Dependencies (17)

- [grpc](https://npm.io/package/grpc.md) ^1.22.2
- [nats](https://npm.io/package/nats.md) ^1.3.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.15
- [ts-nats](https://npm.io/package/ts-nats.md) ^1.2.4
- [upgrade](https://npm.io/package/upgrade.md) ^1.1.0
- [@babel/cli](https://npm.io/package/@babel/cli.md) ^7.5.5
- [protobufjs](https://npm.io/package/protobufjs.md) ^6.8.8
- [@babel/core](https://npm.io/package/@babel/core.md) ^7.5.5
- [@babel/node](https://npm.io/package/@babel/node.md) ^7.5.5
- [grpc-promise](https://npm.io/package/grpc-promise.md) ^1.4.0
- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.5.5
- [@babel/register](https://npm.io/package/@babel/register.md) ^7.5.5
- [@babel/preset-env](https://npm.io/package/@babel/preset-env.md) ^7.5.5
- [kubernetes-client](https://npm.io/package/kubernetes-client.md) ^7.0.1
- [@grpc/proto-loader](https://npm.io/package/@grpc/proto-loader.md) ^0.4.0
- [@kubernetes/client-node](https://npm.io/package/@kubernetes/client-node.md) ^0.8.2
- [@babel/plugin-transform-runtime](https://npm.io/package/@babel/plugin-transform-runtime.md) ^7.5.5

## Recent versions

- 1.7.7 (latest) — 2020-04-27
- 1.7.65 — 2020-02-16
- 1.7.64 — 2020-02-16
- 1.7.63 — 2020-02-16
- 1.7.62 — 2020-02-16
- 1.7.61 — 2020-02-06
- 1.7.6 — 2020-02-06
- 1.7.5 — 2020-02-05
- 1.7.4 — 2020-02-05
- 1.7.2 — 2020-02-05
- 1.7.1 — 2020-02-05
- 1.7.0 — 2020-02-04
- 1.6.994 — 2020-02-04
- 1.6.993 — 2020-02-04
- 1.6.992 — 2020-02-04
- … 55 more at https://npm.io/package/comm-interface/versions

## README

# Comm Interface

Provides simple calls for GRPC and Kube API communication. This module uses [grpc-promise](https://github.com/carlessistare/grpc-promise) and [kubernetes-client](https://github.com/kubernetes-client/javascript) modules as main dependencies.

## Installation

```
npm install comm-interface
```

## GRPC Example

### Client (Unary request)

```typescript
import { GrpcClient } from 'comm-interface';

const address = '0.0.0.0:8080';
const modelPath = 'test.proto';
const serviceName = 'MessageService';
const packageName = 'package';
const debugMode = false;
const protoOpts = {
  keepCase: false,
  longs: String,
  enums: String,
  defaults: true,
  oneofs: true
};
const message = {
  message: "Hello World!"
};

async function main() {
  const grpcClient = new GrpcClient(address, modelPath, serviceName, packageName, debugMode, protoOpts);

  const methodName = 'sendMessage()'; //defined in service: serviceName
  const response = await grpcClient.publishUnary(message, methodName);
  console.log(response);
}

main();
```

### Server (Unary request)

```typescript
import { GrpcServer } from 'comm-interface';

const address = '0.0.0.0:8080';
const modelPath = 'test.proto';
const serviceName = 'MessageService';
const packageName = 'package';
const debugMode = false;
const protoOpts = {
  keepCase: false,
  longs: String,
  enums: String,
  defaults: true,
  oneofs: true
};

function sendMessage(call: any, callback: any) {
  callback(null, call.request);
}

async function main() {
  const grpcServer = new GrpcServer(address, modelPath, serviceName, packageName, { sendMessage }, debugMode, protoOpts);
  grpcServer.start();
}

main();
```

## Kube API Watch Example

```typescript
import { KubeApi } from 'comm-interface';

const path = '/api/v1/namespaces';

function kubeWatchCallback(type: string, obj: any) {
  if (type === 'ADDED') console.log('new object:');
  else if (type === 'MODIFIED') console.log('changed object:');
  else if (type === 'DELETED') console.log('deleted object:');
  else console.log('unknown type: ' + type);
  console.log(obj);
}

function kubeWatchErrorCallback(err: any) {
  throw new Error(err);
}

function main() {
  const kubeApi = new KubeApi(); // empty options load from default kube options
  kubeApi.watchRequest(path, kubeWatchCallback, kubeWatchErrorCallback);
}

main();
```

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