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

@serverless/event-gateway-sdk

v0.12.0

Published

Javascript library for interacting with the [Event Gateway](https://github.com/serverless/event-gateway).

Downloads

40

Readme

Event Gateway JavaScript SDK

Javascript library for interacting with the Event Gateway.

Build Status Known Vulnerabilities

Contents

Background

This is the Javascript SDK for interacting with the Event Gateway, the hub for connecting events to serverless functions. It is designed to work both on the server with Node.js and in the browser.

Target Audience

This SDK can be used both to configure the Event Gateway, by registering functions and subscriptions, and to interact with the Event Gateway, by emitting events from your application to be sent to subscribed functions.

This README is focused on the latter use case -- interacting with the Event Gateway by emitting events. If you're interested in using the Event Gateway SDK to configure the Event Gateway, please check the API reference for the available methods, as well as the main Event Gateway repository. You may also be interested in using the Event Gateway plugin for the Serverless Framework to configure the Event Gateway.

Installation

Node:

npm install @serverless/event-gateway-sdk

Browser:

<script type="text/javascript" src="https://unpkg.com/@serverless/event-gateway-sdk@latest/dist/event-gateway-sdk.min.js"></script>

The EventGateway SDK will then be attached to window e.g. and you can access it via window.EventGatewaySDK

Usage

Use the emit command to emit a CloudEvent payload to your Event Gateway. The event will be received by any function that is subscribed to your event.

// Construct your client
const SDK = require('@serverless/event-gateway-sdk');
const eventGateway = new SDK({
  url: 'https://mytenant-myapp.slsgateway.com',
})

// Emit your event
eventGateway
  .emit({
    eventID: '1',
    eventType: 'user.created',
    cloudEventsVersion: '0.1',
    source: '/services/users',
    contentType: 'application/json',
    data: {
      userID: 'foo'
    }
  }, {
    path: '/users',
    headers: {
      "Authorization": "Bearer 124567890"
    }
  })
  // If a sync subscription, then do something with the response.
  .then(res => res.json())
  .then(json => console.log(json))

The emit() function takes two arguments: an event which is a valid CloudEvent, plus an optional options object to include a path and/or headers to pass with your event.

The function returns a fetch response object. If your event has a sync subscription attached, the fetch response will have the status code and body from the subscription. If not, the response will return a 202 Accepted status code with an empty body.

Constructor

In the example above, we created an Event Gateway client using the application URL from the hosted Event Gateway provided by Serverless, Inc.

You can also use the Event Gateway SDK with your own, self-hosted Event Gateway. Constructor details are listed below.

Parameters

Object:

  • url - string - required, Events API URL
  • configurationUrl - string - optional, Configuration API URL. By default, it's the same as url but with 4001 port
  • space - string - optional, space name, default: default
  • accessKey - string - optional, access key for hosted Event Gateway. Access key is required for using Configuration API methods on hosted Event Gateway
  • fetchClient - object - optional, fetch client

Example

const SDK = require('@serverless/event-gateway-sdk');
const eventGateway = new SDK({
  url: 'http://localhost',
  space: 'mycompany-prod',
  accessKey: '1234abcd'
})

API Reference

For all available methods in the Event Gateway SDK, please see the API reference.

Contribute

If you are interested to contribute we recommend to check out the Contributing document as it explains how to get started and some of the design decisions for this library.