npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@raystack/raccoon

v0.2.2

Published

Raccoon js client publishes events to raccoon server

Downloads

3

Readme

Raccoon Client for Javascript

A JS client library for Raccoon, compatible both in browsers as well as nodejs environment.

Features:

  • Send JSON/Protobuf encoded messages to raccoon server
  • Configurable request wiretype i.e.,JSON/PROTOBUF
  • Retry mechanism

Note: For encoding protobuf messages, this client utilises protobufjs.

Requirements

  • Node.js: Version 20.x or above.
  • Browser: Modern web browser with ES6+ compatibility.

Install

npm i @raystack/raccoon --save

Usage

Construct a new REST client, then pass the available options on the client.

For example:

import { RaccoonClient, SerializationType, WireType } from '@raystack/raccoon';
const raccoonClient = new RaccoonClient({
    serializationType: SerializationType.PROTOBUF,
    wireType: WireType.JSON,
    timeout: 5000,
    url: 'http://localhost:8080/api/v1/events',
    headers: {
        'X-User-ID': 'user-1'
    }
});

Send messages

In the below example, we are sending protobuf messages.

Note: In this case, we only need to send the protobufjs object along with values, the client will take care of encoding the object.

const pageEvent = new clickevents.PageEvent();
pageEvent.eventGuid = "123";
pageEvent.eventName = "page open";

const clickEvent = new clickevents.ClickEvent();
clickEvent.eventGuid = "123";
clickEvent.componentIndex = 1;
clickEvent.componentName = "images";

const events = [
    {
        type: 'test-topic1',
        data: clickEvent
    },
    {
        type: 'test-topic2',
        data: pageEvent
    }
];

raccoonClient.send(events)
    .then(result => {
        console.log('Result:', result);
    })
    .catch(error => {
        console.error('Error:', error);
    });

Note: Here, the PageEvent and ClickEvent are imported from generated protobufjs code.

See complete examples for sending JSON and protobuf messages: examples

Configurations

SerializationType

The serialization type to use for the events being sent to Kafka, either 'PROTOBUF' or 'JSON'.

  • Type: Required
  • Example value: SerializationType.JSON

WireType

The wire configuration using which the request payload should be sent to raccoon server

  • Type: Required
  • Example value: WireType.JSON

url

The URL for the raccoon server.

  • Type: Required
  • Example value: http://localhost:8080/api/v1/events

headers

Custom headers to be included in the HTTP requests.

  • Type: Optional
  • Default value: {}

timeout

The request timeout in milliseconds.

  • Type: Optional
  • Default value: 1000

retryMax

The maximum number of retry attempts for failed requests.

  • Type: Optional
  • Default value: 3

retryWait

The time in milliseconds to wait between retry attempts.

  • Type: Optional
  • Default value: 5000

logger

Logger object for logging.

  • Type: Optional
  • Default value: console

Setting up development environment

Prerequisite Tools

  1. Clone the repo

    $ git clone https://github.com/raystack/raccoon
    $ cd raccoon/clients/js
  2. Install dependencies

    $ npm install
  3. Run the tests. All of the tests are written with jest.

    $ npm test
  4. Run format.

    $ npm run format
  5. Run lint.

    $ npm run lint

Versioning

We use SemVer for versioning. For the versions available, see the tags.