# pyroclast

> Browser + Node.js support for Pyroclast.

Latest version **0.2.3** (published 2017-11-13) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.3 |
| Published | 2017-11-13 |
| First published | 2017-05-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Distributed Masonry |
| Maintainers | mdrogalis, colinhicks |

## Links

- npm: https://www.npmjs.com/package/pyroclast
- Repository: https://github.com/onyx-platform/pyroclast-js
- Homepage: https://github.com/onyx-platform/pyroclast-js#readme
- Issues: https://github.com/onyx-platform/pyroclast-js/issues
- npm.io page: https://npm.io/package/pyroclast

## Dependencies (1)

- [node-fetch](https://npm.io/package/node-fetch.md) ^1.6.3

## Recent versions

- 0.2.3 (latest) — 2017-11-13
- 0.2.2 — 2017-11-13
- 0.2.1 — 2017-10-25
- 0.2.0 — 2017-10-25
- 0.1.8 — 2017-10-05
- 0.1.7 — 2017-10-03
- 0.1.6 — 2017-09-29
- 0.1.5 — 2017-05-30
- 0.1.4 — 2017-05-29
- 0.1.3 — 2017-05-25
- 0.1.2 — 2017-05-24
- 0.1.1 — 2017-05-22
- 0.1.0 — 2017-05-22

## README

## pyroclast-js

Browser + Node.js support for sending events to a Pyroclast topic.

## Installation

```bash
npm install --save pyroclast
```

## Topic APIs

### Write events

First, start the client.

```javascript
const pyroclast = require('pyroclast');

const topicClient = new pyroclast.PyroclastTopicClient({
    writeApiKey: "<your api token>",
    readApiKey: "<your api token>",
    topicId: "<your topic ID>"
});
```

#### Send one event asynchronously

```javascript
topicClient
    .sendEvent({value: {type: "page-visit", page: "/home", timestamp: 1495072835000}})
    .then((result) => {
        // ...
    });
```

#### Send a batch of events asynchronously

```javascript
topicClient
    .sendEvents([
        {value: {type: "page-visit", page: "/home", timestamp: 1495072835000}},
        {value: {type: "page-visit", page: "/home", timestamp: 1495072836000}},
        {value: {type: "page-visit", page: "/home", timestamp: 1495072837000}}
    ])
    .then((results) => {
        // ...
    });
```

### Reading events

Start the client.

```javascript
const pyroclast = require('pyroclast');

const topicClient = new pyroclast.PyroclastTopicClient({
    readApiKey: "<your api token>",
    topicId: "<your topic ID>"
});
```

#### Subscribe to a topic

```javascript
topicClient.subscribe("my-example-subscription").then(
    (consumerInstance) => {
    //...
    })
```

#### Poll subscribed topic

```javascript
consumerInstance.poll()
    .then((result) => {
        // ...
    });
```

#### Commit read records

```javascript
consumerInstance.commit()
    .then((result) => {
        // ...
    });
```

## Supplying a [Fetch](https://fetch.spec.whatwg.org/) implementation

By default:
* In the browser, the native `window.fetch` implementation is used, if available (as in modern browsers).
* In Node.js, `node-fetch` is used.

To override this behavior:
* (Browser/Node.js) Pass the implementation as the `fetchImpl` option, or
* (Browser only) Use a polyfill to define fetch globally.

Note that to support older browsers, you will likely also need a Promise polyfill.

## License

(The MIT License)

Copyright © 2017 Distributed Masonry

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