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

@layerhq/idk

v1.0.1

Published

Layer Integration Development Kit common library

Downloads

19

Readme

Layer IDK

npm version Build Status

This is a Node.js library that is designed to be used with Layer Integration Development Kit (IDK).

It provides common functionality for validating & processing Layer Webhooks and access to common Layer Server API operations.

Initialization

To use this library you need to pass configuration object into the constructor. Configuration object should be a layer_config.json file which is a part of Layer Integration Development Kit.

const LayerIDK = require('@layerhq/idk')
const config = require('./layer_config.json')

const layerIDK = new LayerIDK(config)

Configuration file is generated buy a Layer Integrations command line tool. At a minimum config JSON has the following format:

{
  "app_id": "layer:///apps/staging/ffffffff-ffff-ffff-ffff-ffffffffffff",
  "webhook": {
    "secret": "supersecret",
    "events": ["Message.created"]
  },
  "api": {
    "token": "abcdefg"
  }
}

Webhook

Every integration is powered by a Layer Webhook which is registered to listen for a set of events in an application.

.webhook(headers, body)

Validate and process a webhook by passing in HTTP headers object and POST request body. This is a synchronous function which will return webhook payload or throw an error that needs to be captured and handled.

Arguments

  • headers - Webhook HTTP headers
  • body - Webhook HTTP request body as a JSON string

Example

try {
  const webhook = layerIDK.webhook(headers, body)
  // webhook payload
} catch (err) {
  console.error(err)
}

Logger

We provide a logger interface to unify log severity levels, abstract some of the Cloud Provider specific functionality and enable optional monitoring capabilities.

.logger(context)

Get logger interface by passing in the cloud function context object.

Arguments

  • context - Cloud function context object (AWS or Azure)

Example

const log = layerIDK.logger(context)

log.info('Hello world', { foo: 'bar' })
log.error('Error', new Error('Oops'))

Available levels: debug, info, warn, error, none. Every level accepts the following function parameters: (message, object)

You can set log level by setting LOG_LEVEL=error env variable.

Monitoring

Logger has a built in monitoring capabilities. Read about monitoring here.

API

Access common Layer Server API operations via .api namespace. Read API documentation here.

Utils

These are the utility functions exposed statically via LayerIDK class. Read documentation here.

AWS Example

The following example shows how to use Amazon AWS API Gateway inside your Serverless handler.

const LayerIDK = require('@layerhq/idk')
const config = require('./layer_config.json')

const layerIDK = new LayerIDK(config)

exports.webhook = (event, context, callback) => {
  const log = layerIDK.logger(contex)

  try {
    const webhook = layerIDK.webhook(event.headers, event.body)
    // webhook payload

    log.info('Webhook:', webhook)
    callback(null, { statusCode: 200 })
  } catch (err) {
    log.error('Webhook:', err)
    callback(err)
  }
}