# @wmakeev/lambda-node-standard-response

> Standard response spec implementation for aws lambda node functions

Latest version **2.0.1** (published 2017-11-19) · ISC license · 0 weekly downloads

## Install

```sh
npm install @wmakeev/lambda-node-standard-response
pnpm add @wmakeev/lambda-node-standard-response
yarn add @wmakeev/lambda-node-standard-response
bun add @wmakeev/lambda-node-standard-response
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2017-11-19 |
| First published | 2017-04-13 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Vitaliy V. Makeev |
| Maintainers | wmakeev |
| Keywords | standard, response, lambda, aws |

## Links

- npm: https://www.npmjs.com/package/@wmakeev/lambda-node-standard-response
- Repository: https://github.com/wmakeev/standard-response/tree/master/packages/lambda-node-standard-response
- Homepage: https://github.com/wmakeev/standard-response
- Issues: https://github.com/wmakeev/standard-response/issues
- npm.io page: https://npm.io/package/@wmakeev/lambda-node-standard-response

## Dependencies (1)

- [is-promise](https://npm.io/package/is-promise.md) ^2.1.0

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 2.0.1 (latest) — 2017-11-19
- 2.0.0 — 2017-11-16
- 1.2.0 — 2017-09-23
- 1.1.1 — 2017-08-15
- 1.1.0 — 2017-06-19
- 1.0.0 — 2017-04-13

## README

lambda-node-standard-response
=============================

[![npm](https://img.shields.io/npm/v/@wmakeev/lambda-node-standard-response.svg?maxAge=1800&style=flat-square)](https://www.npmjs.com/package/@wmakeev/lambda-node-standard-response)

> Standard response spec implementation for aws lambda node functions

## Installation

```
$ npm install @wmakeev/lambda-node-standard-response
```

## Usage

Example of aws lambda function code:

```js
const standardResponse = require('@wmakeev/lambda-node-standard-response')

function doStuff (ev) {
  return ev.value
}

function doStuffAsync (ev) {
  return Promise.resolve(ev.value)
}

exports.default = standardResponse(function (ev, ctx) {
  return ev.async ? doStuffAsync(ev) : doStuff(ev)
}, { debug: true })
```

`doStuff` can be sync or async (in case of async it should return `Promise`)

Lambda event:

```json
{
  "async": "true",
  "value": "Hello world!"
}
```


Lambda response (same in sync and async cases):

```json
{
  "ok": true,
  "result": "Hello world!",
  "format": "2.0"
}
```

Lambda response in the case `standardResponse` caught an error:

```json
{
  "ok": false,
  "description": "Some error message",  // equal to error.message field or 'Unknown error' (if handler returns not Error type without not empty message string field or string type error)
  "name": "Error",                      // equal to error.name
  "code": "some code",                  // equal to error.code
  "stack": ['stack trace lines'],       // specified if `options.debug` is true
  "format": "2.0"
}
```

## API

### `standardResponse(handler: function(ev, context), options: object): function(event, context, cb)`

- `handler` - sync or async (returns Promise) function
- `options.debug` - `boolean` value (if `true`, then error response will include `stack` property)

**returns:**

You `handler` wrapped in AWS Lambda standard handler style function `function(event, context, cb)`

---
_Source: https://npm.io/package/@wmakeev/lambda-node-standard-response · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
