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

@buildable/client

v1.0.1

Published

Buildable is a fully managed event bus lets you send and receive data across mission-critical cloud apps, databases and warehouses.

Downloads

8

Readme

@buildable/client

Buildable npm version GitHub contributors GitHub license Twitter Follow

Buildable is the easiest way to collect, stream, transform and action your backend system events. Buildable simplifies the process of communicating between services or cloud apps via events.

This library allows you to quickly and easily emit and listen on events via Node.js.

Setup

In order to use emit and listen on events, you'll need a Buildable account and Secret Key. Follow these steps:

  1. Create an account at buildable.dev
  2. Connect a Node.js Source within the Sources page
  3. Copy the Secret Key from the Setup tab
  4. Install the package (see below)
  5. Start emitting your events

Install Package

Install the @buildable/client NPM package in your working code environment:

> npm install @buildable/client

Emitting Events

The emit requires:

  1. event - The name of the event
  2. payload - The data of the event

Once an event is emitted, it will be visible immediately in the Live Events feed in your Buildable developer dashboard.

Using NodeJS

const { createClient } = require('@buildable/client');

const client = createClient(process.env.BUILDABLE_SECRET_KEY);

client.emit("user.created", { 
  name: "John Doe"
});

Want to use cURL instead?

curl --location --request POST 'https://events.buildable.dev/emit' \
  --header 'X-Buildable-Secret: <YOUR SECRET KEY>' \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "event": "user.created",
    "payload": {
      "name": "John Doe"
    }
}'

Listening on Events

What is a transaction?

A transaction is an action that can be triggered when an event is received. An event can have multiple transactions. Each transaction has:

  1. An input value
  2. An output value
  3. A unique transaction key (txKey) per event

Transacting on custom events from your Node.JS source

const { createClient } = require('@buildable/client');

const client = createClient(process.env.BUILDABLE_SECRET_KEY);

// Transact on `user.created`
client.on("user.created", async ({ event, payload }) => {
  console.log("Receieved event with payload: ", payload);

  // Any value returned here will be set as the transaction's output
  return {
    success: true
  };
});

Transacting on platform events from your cloud app sources

When listening on events from cloud apps, simply add two additional options to the listener:

const { createClient } = require('@buildable/client');

const client = createClient(process.env.BUILDABLE_SECRET_KEY);

// Listen on `customer.created` from Stripe
client.on("customer.created", async ({ event, payload }) => {
  console.log("Receieved message with payload: ", payload);

  // Any value returned here will be set as the transaction's output
}, {
  platform: "stripe", // Platform name
  label: "my-stripe-connection" // Connection name
});

Multiple transactions on an event

In order to trigger multiple transactions on the same event, you must specify a custom transaction key (txKey). For example, if two services need to listen on the same event and trigger different custom logic, each service must pass a unique txKey to the listener.

const { createClient } = require('@buildable/client');

const client = createClient(process.env.BUILDABLE_SECRET_KEY);

// Transaction #1 on `user.created` from service A
client.on("user.created", async ({ event, payload }) => {
  // Set the notification.sent transaction output
  return await sendNotification(payload);
}, {
  txKey: "notification.sent"
});

// Transaction #2 on `user.created` from service B
client.on("user.created", async ({ event, payload }) => {
  // Set the salesforce.customer.created transaction output
  return await createCustomerOnSalesForce(payload);
}, {
  txKey: "salesforce.customer.created"
});

*By default, the txKey is set to sdk.{{EVENT_NAME}}

Transacting on historical events

In order to transact on events that have already been emitted in the past, simply pass in the additional configuration argument since. For example, to transact on messages from 10 days ago:

client.on("user.created", async ({ event, payload }) => {
  // Set the notification.sent transaction output
  return await sendNotification(payload);
}, {
  txKey: "notification.sent",
  since: Date.now() - (10 * 24 * 60 * 60 * 1000) // Since 10 days ago
});

API

Alternatively, you can use the Buildable API. Learn more about it at docs.buildable.dev

Need More Help?

💻 Website: https://buildable.dev

📄 Docs: https://docs.buildable.dev

💬 Discord: https://discord.com/invite/47AJ42Wzys

🐦 Twitter: https://twitter.com/BuildableHQ

License

© 2022, Buildable Technologies Inc. - Released under the MIT License