Skip to content

Commit 794d713

Browse files
committed
update libs, simplify unit testing
1 parent 3df3dd4 commit 794d713

File tree

15 files changed

+3186
-3948
lines changed

15 files changed

+3186
-3948
lines changed

CHANGELOG.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,25 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html)
66

7+
## [3.1.2]  (2020-02-11)
8+
9+
### Fixed
10+
11+
- Support additional properties on content-type
12+
- Add correct content-type header for JSON stringified API responses
13+
- Update old libraries
14+
15+
## [3.1.1]  (2020-01-22)
16+
17+
### Added
18+
19+
- Add a 'not authorized' response handler to the api wrapper
20+
721
## [3.1.0]  (2020-01-20)
822

923
### Changed
1024

11-
- Missing signature params as undefined instead of null to allow for default values
25+
- Default signature params to undefined instead of null to allow for default values
1226
- Updated libraries
1327

1428
## [3.0.0]  (2020-01-05)
@@ -156,7 +170,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/),
156170
- Update older libraries
157171
- Now publish from Git tags instead of master pushes
158172

159-
[3.0.1]: https://github.com/manwaring/lambda-wrapper/compare/v3.0.0...v3.1.0
173+
[3.1.2]: https://github.com/manwaring/lambda-wrapper/compare/v3.1.1...v3.1.2
174+
[3.1.1]: https://github.com/manwaring/lambda-wrapper/compare/v3.1.0...v3.1.1
175+
[3.1.0]: https://github.com/manwaring/lambda-wrapper/compare/v3.0.0...v3.1.0
160176
[3.0.0]: https://github.com/manwaring/lambda-wrapper/compare/v2.1.1...v3.0.0
161177
[2.1.1]: https://github.com/manwaring/lambda-wrapper/compare/v2.1.0...v2.1.1
162178
[2.1.0]: https://github.com/manwaring/lambda-wrapper/compare/v2.0.1...v2.1.0

README.md

Lines changed: 38 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,31 @@
11
<p align="center">
2-
<img height="150" src="https://avatars0.githubusercontent.com/u/36457275?s=400&u=16d355f384ed7f8e0655b7ed1d70ff2e411690d8&v=4e">
3-
<img height="150" src="https://user-images.githubusercontent.com/2955468/44874383-0168f780-ac69-11e8-8e51-774678cbd966.png">
2+
<img height="140" src="https://avatars0.githubusercontent.com/u/36457275?s=400&u=16d355f384ed7f8e0655b7ed1d70ff2e411690d8&v=4e">
3+
<img height="140" src="https://user-images.githubusercontent.com/2955468/44874383-0168f780-ac69-11e8-8e51-774678cbd966.png">
44
</p>
55

6-
[![version]][version-url] [![downloads]][downloads-url] [![coverage]][coverage-url] [![size]][size-url] [![license]][license-url]
6+
<p align="center">
7+
<a href="https://npmjs.com/package/@manwaring/lambda-wrapper">
8+
<img src="https://flat.badgen.net/npm/v/@manwaring/lambda-wrapper?icon=npm&label=npm@latest"></a>
9+
<a href="https://www.npmjs.com/package/@manwaring/lambda-wrapper">
10+
<img src="https://flat.badgen.net/npm/dt/@manwaring/lambda-wrapper?icon=npm"></a>
11+
<a href="https://codecov.io/gh/manwaring/lambda-wrapper">
12+
<img src="https://flat.badgen.net/codecov/c/github/manwaring/lambda-wrapper/?icon=codecov"></a>
13+
<a href="https://packagephobia.now.sh/result?p=@manwaring/lambda-wrapper">
14+
<img src="https://flat.badgen.net/packagephobia/install/@manwaring/lambda-wrapper"></a>
15+
<a href="https://www.npmjs.com/package/@manwaring/lambda-wrapper">
16+
<img src="https://flat.badgen.net/npm/license/@manwaring/lambda-wrapper"></a>
17+
</p>
718

8-
[![build]][build-url] [![dependabot]][dependabot-url] [![dependency]][dependency-url] [![dev-dependency]][dev-dependency-url]
19+
<p align="center">
20+
<a href="https://circleci.com/gh/manwaring/lambda-wrapper">
21+
<img src="https://flat.badgen.net/circleci/github/manwaring/lambda-wrapper/master?icon=circleci"></a>
22+
<a href="https://flat.badgen.net/dependabot/manwaring/lambda-wrapper">
23+
<img src="https://flat.badgen.net/dependabot/manwaring/lambda-wrapper/?icon=dependabot&label=dependabot"></a>
24+
<a href="https://david-dm.org/manwaring/lambda-wrapper">
25+
<img src="https://flat.badgen.net/david/dep/manwaring/lambda-wrapper"></a>
26+
<a href="https://david-dm.org/manwaring/lambda-wrapper?type=dev">
27+
<img src="https://flat.badgen.net/david/dev/manwaring/lambda-wrapper/?label=dev+dependencies"></a>
28+
</p>
929

1030
# AWS Lambda wrapper library
1131

@@ -81,19 +101,20 @@ export const handler = api(async ({ body, path, success, error }) => {
81101
### Properties and methods available on wrapper signature
82102

83103
```ts
84-
interface ApiSignature {
104+
export interface ApiSignature {
85105
event: APIGatewayEvent; // original event
86-
body: any; // JSON or form parsed body payload if exists (based on content-type headers), otherwise the raw body object
87-
path: { [name: string]: string }; // path param payload as key-value pairs
88-
query: { [name: string]: string }; // query param payload as key-value pairs
89-
headers: { [name: string]: string }; // headers param payload as key-value pairs
90-
testRequest: boolean; // indicates if this is a test request, based on presence of headers matching 'Test-Request' or process.env.TEST_REQUEST_HEADER
91-
auth: any; // auth context from custom authorizer
92-
success(payload?: any, replacer?: (this: any, key: string, value: any) => any): ApiResponse; // returns 200 status with payload
93-
invalid(errors?: string[]): ApiResponse; // returns 400 status with errors
94-
notFound(message?: string): ApiResponse; // returns 404 status with message
95-
redirect(url: string): ApiResponse; // returns 302 redirect with new url
96-
error(error?: any): ApiResponse; // returns 500 status with error
106+
body: any; // JSON parsed body payload if exists (otherwise null)
107+
path: { [name: string]: string }; // path param payload as key-value pairs if exists (otherwise null)
108+
query: { [name: string]: string }; // query param payload as key-value pairs if exists (otherwise null)
109+
headers: { [name: string]: string }; // header payload as key-value pairs if exists (otherwise null)
110+
testRequest: boolean; // indicates if this is a test request - looks for a header matching process.env.TEST_REQUEST_HEADER (dynamic from application) or 'Test-Request' (default)
111+
auth: any; // auth context from custom authorizer if exists (otherwise null)
112+
success(payload?: any, replacer?: (this: any, key: string, value: any) => any): ApiResponse; // returns 200 status code with optional payload as body
113+
invalid(errors?: string[]): ApiResponse; // returns 400 status code with optional errors as body
114+
notFound(message?: string): ApiResponse; // returns 404 status code with optional message as body
115+
notAuthorized(message?: string): ApiResponse; // returns 403 status code with optional message as body
116+
redirect(url: string): ApiResponse; // returns 302 status code (redirect) with new url
117+
error(error?: any): ApiResponse; // returns 500 status code with optional error as body
97118
}
98119

99120
interface ApiResponse {
@@ -276,32 +297,6 @@ interface WrapperSignature {
276297

277298
# Example projects
278299

279-
THere is one [working example](examples) of how this package can be used in a simple 'hello world' serverless application:
300+
There is one [working example](examples) of how this package can be used in a simple 'hello world' serverless application:
280301

281302
1. [Using the Serverless Framework and TypeScript](examples/ts)
282-
283-
<!-- Badge icons -->
284-
285-
[version]: https://flat.badgen.net/npm/v/@manwaring/lambda-wrapper?icon=npm&label=npm@latest
286-
[downloads]: https://flat.badgen.net/npm/dt/@manwaring/lambda-wrapper?icon=npm
287-
[coverage]: https://flat.badgen.net/codecov/c/github/manwaring/lambda-wrapper/?icon=codecov
288-
[size]: https://flat.badgen.net/packagephobia/install/@manwaring/lambda-wrapper
289-
[license]: https://flat.badgen.net/npm/license/@manwaring/lambda-wrapper/
290-
[language]: https://flat.badgen.net/badge/typescript/typescript/?icon&label
291-
[style]: https://flat.badgen.net/badge/code%20style/prettier?color=purple&icon=terminal&label
292-
[build]: https://flat.badgen.net/circleci/github/manwaring/lambda-wrapper/master?icon=circleci
293-
[dependabot]: https://flat.badgen.net/dependabot/manwaring/lambda-wrapper/?icon=dependabot&label=dependabot
294-
[dependency]: https://flat.badgen.net/david/dep/manwaring/lambda-wrapper
295-
[dev-dependency]: https://flat.badgen.net/david/dev/manwaring/lambda-wrapper/?label=dev+dependencies
296-
297-
<!-- Badge URLs -->
298-
299-
[version-url]: https://npmjs.com/package/@manwaring/lambda-wrapper
300-
[downloads-url]: https://www.npmjs.com/package/@manwaring/lambda-wrapper
301-
[coverage-url]: https://codecov.io/gh/manwaring/lambda-wrapper
302-
[size-url]: https://packagephobia.now.sh/result?p=@manwaring/lambda-wrapper
303-
[license-url]: https://www.npmjs.com/package/@manwaring/lambda-wrapper
304-
[build-url]: https://circleci.com/gh/manwaring/lambda-wrapper
305-
[dependabot-url]: https://flat.badgen.net/dependabot/manwaring/lambda-wrapper
306-
[dependency-url]: https://david-dm.org/manwaring/lambda-wrapper
307-
[dev-dependency-url]: https://david-dm.org/manwaring/lambda-wrapper?type=dev

0 commit comments

Comments
 (0)