Skip to content

Repository files navigation

@dustfoundation/serverless-kit

CINPM VersionMinimum Node.js Version

Serverless Kit for fast development.

Installation

npm install --save @dustfoundation/serverless-kit

Features

Authorizer Groups Validation

// User must have at least one of specified groups (moderator OR admin)hasAnyGroup(event.requestContext.authorizer!.groups.split(';'),['moderator','admin']);// => boolean
// User must have all specified groups (moderator AND admin)hasAllGroups(event.requestContext.authorizer!.groups.split(';'),['moderator','admin']);// => boolean

Parse Request Body (JSON)

constbody=parseRequestBody<{name: 'Elon'}>(event.body,event.headers);// Check Content-Type=application/jsonconstbody=parseRequestBody<{name: 'Elon'}>(event.body,false);// Skip Content-Type=application/jsonif(!body){returnBadRequest();}// => { name: 'Elon' } | null

Pretty Responses

// Success responsereturnSuccess();// 200// Success response with body (authomatic JSON.stringify())returnSuccess().withBody({name: 'Elon'});// Success response with body and headersreturnSuccess().withBody({name: 'Elon'}).withHeaders({'test-header': 1});returnSuccess().withBody({name: 'Elon'}).withMultiValueHeaders({'test-header': [1]});// Success response with base64Encoded enabled (for files)returnSuccess().withBase64Encoded();// Other responses (withBody and other props can also be applied)returnCreated();// 201returnAccepted();// 202returnNoContent();// 204returnBadRequest();// 400returnUnauthorized();// 401returnForbidden();// 403returnNotFound();// 404returnConflict();// 409returnTooManyRequests();// 429returnInternalServerError();// 500returnBadGateway();// 502returnGatewayTimeout();// 504// Custom status codesreturnResponseBuilder(000).withBody(...);// 000

About

Serverless Kit for fast development

Topics

Resources

Stars

2 stars

Watchers

2 watching

Forks

Used by

Contributors

Languages