4.0.0 • Published 1 year ago

@dustfoundation/serverless-kit v4.0.0

Weekly downloads
-
License
-
Repository
github
Last release
1 year ago

@dustfoundation/serverless-kit

CI NPM Version Minimum 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)

const body = parseRequestBody<{ name: 'Elon' }>(event.body, event.headers); // Check Content-Type=application/json
const body = parseRequestBody<{ name: 'Elon' }>(event.body, false); // Skip Content-Type=application/json
if (!body) {
  return BadRequest();
}
// => { name: 'Elon' } | null

Pretty Responses

// Success response
return Success(); // 200

// Success response with body (authomatic JSON.stringify())
return Success().withBody({ name: 'Elon' });

// Success response with body and headers
return Success().withBody({ name: 'Elon' }).withHeaders({ 'test-header': 1 });
return Success().withBody({ name: 'Elon' }).withMultiValueHeaders({ 'test-header': [1] });

// Success response with base64Encoded enabled (for files)
return Success().withBase64Encoded();

// Other responses (withBody and other props can also be applied)
return Created(); // 201
return Accepted(); // 202
return NoContent(); // 204
return BadRequest(); // 400
return Unauthorized(); // 401
return Forbidden(); // 403
return NotFound(); // 404
return Conflict(); // 409
return TooManyRequests(); // 429
return InternalServerError(); // 500
return BadGateway(); // 502
return GatewayTimeout(); // 504

// Custom status codes
return ResponseBuilder(000).withBody(...); // 000
4.0.0

1 year ago

3.2.0-beta.8

1 year ago

3.2.0-beta.9

1 year ago

3.1.2

1 year ago

3.2.0-beta.6

1 year ago

3.1.1

1 year ago

3.2.0-beta.7

1 year ago

3.2.0-beta.4

1 year ago

3.2.0-beta.5

1 year ago

3.2.0-beta.2

1 year ago

3.2.0-beta.3

1 year ago

3.2.0-beta.0

1 year ago

3.2.0-beta.1

1 year ago

3.2.0-beta.13

1 year ago

3.2.0-beta.12

1 year ago

3.2.0-beta.11

1 year ago

3.2.0-beta.10

1 year ago

2.3.0

2 years ago

2.4.1

2 years ago

2.4.0

2 years ago

2.2.1

2 years ago

2.2.0

2 years ago

2.1.0

2 years ago

2.0.0

2 years ago

2.0.0-rc.1

2 years ago