# @sobol/sdk

> A SDK for writing Sobol apps.

Latest version **2.0.0** (published 2020-01-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install @sobol/sdk
pnpm add @sobol/sdk
yarn add @sobol/sdk
bun add @sobol/sdk
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2020-01-07 |
| First published | 2019-10-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 9.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Sobol |
| Maintainers | leifdejong, victor.leipnik, vlad.kutsenko |

## Links

- npm: https://www.npmjs.com/package/@sobol/sdk
- npm.io page: https://npm.io/package/@sobol/sdk

## Dependencies (3)

- [lodash](https://npm.io/package/lodash.md) ^4.17.15
- [express](https://npm.io/package/express.md) ^4.17.1
- [body-parser](https://npm.io/package/body-parser.md) ^1.19.0

## Recent versions

- 2.0.0 (latest) — 2020-01-07
- 1.5.0 — 2019-10-07

## README

# @sobol/sdk

A JavaScript SDK for developing integrations with Sobol.

For our **Starter App**, see [@sobol/app](https://www.npmjs.com/package/@sobol/app).

## Installation

```bash
npm install @sobol/sdk
```

## Webhook

To bootstrap a webhook, use the `webhook` class as follows:

```javascript
const Client = require('@sobol/client');
const Webhook = require('@sobol/sdk/webhook');
const {
  WEBHOOK_MESSAGE_TYPE
} = require('@sobol/sdk/constants');

// === Configure Webhook ===
Webhook.configure({
  url: 'https://example.com/production/events/sobol',
  events: [
    'goal:created',
    'goal:updated',
    'goal:deleted',
  ],
  client: Client, // must be already configured
});

// === Event Handler ===
// - upon receiving some webhook event, verify handshake
const msg = '<some message object from sobol>';
const { type } = msg;

if (type === WEBHOOK_MESSAGE_TYPE.UrlVerification) {
  Webhook.verify(msg); // perform handshake
} else {
  console.log(msg);
}
```

### Options

| Option           | Type     | Description                                                  | Default                                   |
|------------------|----------|--------------------------------------------------------------|-------------------------------------------|
| `url`            | String   | Webhook URL                                                  | `''`                                      |
| `events`         | String   | Webhook Events                                               | `[]`                                      |
| `client`         | Object   | [@sobol/client](https://www.npmjs.com/package/@sobol/client) |                                           |

## Webhook Server

To bootstrap a webhook server, use the `webhook/server` class as follows:

```javascript
const Webhook = require('@sobol/sdk/webhook');
const WebhookServer = require('@sobol/sdk/webhook/server');

// === Server Setup ===
WebhookServer.configure({
  port: 8080,
  webhook: Webhook, // must be already configured
}, (/* server, app, router */) => {
  // customize express app here
});

// === Register Webhook Handler ===
WebhookServer.registerWebhook((msg) => {
  log(`[${APP_NAME}] ... sobol webhook event received:`, JSON.stringify(msg));
});

// === Start Server ===
WebhookServer.listen();
```

### Options

| Option           | Type     | Description                                                  | Default                                   |
|------------------|----------|--------------------------------------------------------------|-------------------------------------------|
| `port`           | Number   | Port to listen                                               | `8085`                                    |
| `prefix`         | String   | Prefix for route                                             | `/:env/events`                            |
| `webhook`        | Object   | [@sobol/sdk/webhook](#webhook)                               |                                           |

## Help and Feedback

For help and feedback, please send us an email to team@sobol.io and we will respond as soon as possible.

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