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

@softchef/lambda-events

v1.1.81

Published

[![npm version](https://badge.fury.io/js/%40softchef%2Flambda-events.svg)](https://badge.fury.io/js/%40softchef%2Flambda-events) ![Release](https://github.com/SoftChef/lambda-events/workflows/Release/badge.svg) ![npm](https://img.shields.io/npm/dt/@softch

Downloads

648

Readme

Lambda Events

npm version Release npm

Installation

// NPM
npm install @softchef/lambda-events

// Yarn
yarn add @softchef/lambda-events

RestApi

JavaScript require

const { RestApi } = require('@softchef/lambda-events');
or
const { Request, Response } = require('@softchef/lambda-events');

TypeScript import

import { RestApi } from '@softchef/lambda-events';
or
import { Request, Response } from '@softchef/lambda-events';

RestApi.Request / Request class:

const request = new RestApi.Request(event);
or
const request = new Request(event);

Methods

Get Parameters

const value = request.parameter(key);

// Get URL path paramter, ex: /Users/{username}, 

const username = request.parameter('username');

Get QueryStrings

const value = request.get(key, defaultValue);

// Get query string, ex: ?filter=hello

const value = request.get('filter', null);

Get Post data / Body

const value = request.input(key, defaultValue);

// Get post field data, ex: name=John

const name = request.input('name', 'Who');

const inputs = request.inputs(keys);

// Get post mulitple fields data, ex: name=John&enabled=true,

const inputs = request.inputs(['name', 'enabled']);

// inputs: { name: 'John', enabled: true }

Validate Inputs or QueryStrings

const validated = request.validate(keysProvider);

// Validate input data, keysProvider is an callback, keysProvider(joi) please return a Joi schemas

RestApi.Response / Response class:

const response = new RestApi.Response();
or
const response = new Response();

Methods

Response JSON

response.json(data, httpStatusCode);

// If the API request are success, use response.json and give a JSON object data to return client. ex:

response.json({ hello: "world"}, 200);

Response error

response.error(error, httpStatusCode);

// If the API request are failure, use response.error and give a Error object to return client. ex:

response.error(
  new Error('Invalid input data'),
  422
)

CustomResource

CloudFormation can use CustomResource to invoke a Lambda function. You will get request type, properties from event, and response to stacks when process success/failure.

// JavaScript require
const { CustomResource } = require('@softchef/lambda-events');

// TypeScript import
import { CustomResource } from '@softchef/lambda-events';

CustomResource.Request class:

const request = new CustomResource.Request(event);

Methods

Get Properties

const value = request.property(key);

// Get the CustomResource property by key. ex:

const tableName = request.property('DynamoDbTableName');

// Will return the reference table name from stacks.

Get RequestType

const isOn = request.on(requestType);

// The request type is the stacks process status, allow: Create / Update / Delete. ex:

const isCreate = request.on('create');

// When stacks has first time to create will be true

const isCreateOrUpdate = request.on(['create', 'update']);

// When stacks has first time to create or any update will be true

CustomResource.Response class:

const response = new CustomResource.Response(event);

Methods

Response success to stacks

response.success(returnData): Promise;

// You can return data to stacks. ex:

await response.success({
  time: Date.now()
});

// In the stacks can reference. CDK ex:

new CfnOutput(stack, id, {
  value: customResource.getAtt('time')
});

Response failure to stacks

response.failed(error): Promise;

// If process has any error, you can report the error message to response stacks. ex:

await response.failed(
  new Error('Something wrong.')
);

// The stacks will rollback and display your error message.

Future

  • Support more lambda events
    • Cognito Trigger
    • S3 Trigger
    • EventBridge event source
    • SQS event source
    • Kinesis Data Firehose event source
    • more...