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/fdk

v0.7.1

Published

Node.js library to improve developer experience developing Serverless applications.

Downloads

8,568

Readme

Function Development Kit (aka FDK)

Node.js library to improve developer experience developing Serverless applications.

It contains a client to configure and interact with the Event Gateway.

Build Status

Install (Node)

npm install @serverless/fdk

Install (Browser)

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

The FDK then will be attached to window e.g. and you can access it via window.fdk

Create an Event Gateway Client

const fdk = require('@serverless/fdk');
const eventGateway = fdk.eventGateway({
  url: 'http://localhost',
})

Optional Properties for eventGateway

{
  // defaults to the provide URL + default config port 4001
  configurationUrl: 'http://localhost:4001'
  // optional property to provide their own http lib
  fetchClient: fetch
}

Invoke a Function

eventGateway.invoke({
  functionId: "createUser",
  data: { name: "Max" },
})

Returns a Promise with the response.

The value of data is converted using JSON.stringify by default since the default dataType is application/json. This is not happening and the value is passed as it is when the property dataType is provided.

Invoke a Function with a Custom Data Type

eventGateway.invoke({
  functionId: "createUser",
  data: "Max",
  dataType: "text/plain",
})

Emit an Event

eventGateway.emit({
  event: "userCreated",
  data: { name: "Max" },
})

Returns a Promise and when resolved the response only indicates if the Event Gateway received the event. Responses from any subscribed functions are not part of the response.

The value of data is converted using JSON.stringify by default since the default dataType is application/json. This is not happening and the value is passed as it is when the property dataType is provided.

Emit an Event with a Custom Data Type

eventGateway.emit({
  event: "userCreated",
  data: "This is a string message.",
  dataType: "text/plain",
})

Configure an Event Gateway

Configure accepts an object of function and subscription definitions. The idea of exposing one configuration function is to provide developers with convenient utility to configure an Event Gateway in one call rather then dealing with a chain of Promise based calls. Nevertheless in addition we expose a wrapper function for each low-level API call to the Event Gateway described in this section.

eventGateway.configure({
  // list of all the functions that should be registered
  functions: [
    {
      functionId: "helloWorld"
      provider: {
        type: "awslambda"
        arn: "xxx",
        region: "us-west-2",
      }
    },
    {
      functionId: "sendWelcomeMail"
      provider: {
        type: "gcloudfunction"
        name: "sendWelcomeEmail",
        region: "us-west-2",
      }
    }
  ],
  // list of all the subscriptions that should be created
  subscriptions: [
    {
      event: "http",
      method: "GET",
      path: "/users",
      functionId: "helloWorld"
    },
    {
      event: "user.created",
      functionId: "sendEmail"
    }
  ]
})

Returns a promise which contains all the same list of functions and subscriptions in the same structure and order as provided in the configuration argument.

eventGateway.configure({ config })
  .then((response) => {
    console.log(response)
    // {
    //   functions: [
    //     { functionId: 'xxx', … },
    //     { functionId: 'xxx', … }
    //   ],
    //   subscriptions: [
    //     { subscriptionId: 'xxx', … },
    //     { subscriptionId: 'xxx', … }
    //   ]
    // }
  })

Reset the configuration

Reset removes all the existing subscriptions and functions.

eventGateway.resetConfiguration()

Further Event Gateway Functions

// Returns a function
eventGateway.registerFunction({
  functionId: "sendEmail"
  provider: {
    type: "awslambda"
    arn: "xxx",
    region: "us-west-2",
  }
})

// Returns undefined
eventGateway.deleteFunction({ functionId: "sendEmail" })

// Returns an Array of functions
eventGateway.listFunctions()

// Returns a subscription: { subscriptionId, event, functionId}
eventGateway.subscribe({
  event: "user.created",
  functionId: "sendEmail"
})

// Returns undefined
eventGateway.unsubscribe({
  subscriptionId: "user.created-sendEmail"
})

// Returns an Array of subscriptions
eventGateway.listSubscriptions()

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.