Skip to content

Commit 3b92e6e

Browse files
committed
add support for websocket connections
1 parent 333e63f commit 3b92e6e

File tree

8 files changed

+2003
-721
lines changed

8 files changed

+2003
-721
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,5 @@ typings/
6262

6363
# next.js build output
6464
.next
65+
66+
.vscode

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ 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.6.0]  (2020-06-21)
8+
9+
### Added
10+
11+
- Add support for Websocket connections
12+
13+
### Updated
14+
15+
- Updated all libraries to latest
16+
717
## [3.5.0]  (2020-05-10)
818

919
### Changed
@@ -219,6 +229,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/),
219229
- Update older libraries
220230
- Now publish from Git tags instead of master pushes
221231

232+
[3.6.0]: https://github.com/manwaring/lambda-wrapper/compare/v3.5.0...v3.6.0
222233
[3.5.0]: https://github.com/manwaring/lambda-wrapper/compare/v3.4.0...v3.5.0
223234
[3.4.0]: https://github.com/manwaring/lambda-wrapper/compare/v3.3.3...v3.4.0
224235
[3.3.3]: https://github.com/manwaring/lambda-wrapper/compare/v3.3.1...v3.3.3

README.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,22 +103,47 @@ export const handler = api<CustomInterface>(async ({ body, path, success, error
103103
### Properties and methods available on wrapper signature
104104

105105
```ts
106-
export interface ApiSignature<T> {
106+
export interface ApiSignature<T = any> {
107107
event: APIGatewayEvent; // original event
108108
body: T; // JSON parsed body payload if exists (otherwise undefined)
109+
requestContext: WebsocketRequestContext; // websocket connection payload
109110
path: { [name: string]: string }; // path param payload as key-value pairs if exists (otherwise undefined)
110111
query: { [name: string]: string }; // query param payload as key-value pairs if exists (otherwise undefined)
111112
headers: { [name: string]: string }; // header payload as key-value pairs if exists (otherwise undefined)
112113
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)
113-
auth: any; // auth context from custom authorizer if exists (otherwise null)
114+
auth: any; // auth context from custom authorizer if exists (otherwise undefined)
114115
success(payload?: any, replacer?: (this: any, key: string, value: any) => any): ApiResponse; // returns 200 status code with optional payload as body
115116
invalid(errors?: string[]): ApiResponse; // returns 400 status code with optional errors as body
116117
notFound(message?: string): ApiResponse; // returns 404 status code with optional message as body
117-
notAuthorized(message?: string): ApiResponse; // returns 401 status code with optional message as body
118+
notAuthorized(message?: string): ApiResponse; // returns 403 status code with optional message as body
118119
redirect(url: string): ApiResponse; // returns 302 status code (redirect) with new url
119120
error(error?: any): ApiResponse; // returns 500 status code with optional error as body
120121
}
121122

123+
export interface WebsocketRequestContext {
124+
accountId: string;
125+
apiId: string;
126+
connectedAt?: number;
127+
connectionId?: string;
128+
domainName?: string;
129+
domainPrefix?: string;
130+
eventType?: string;
131+
extendedRequestId?: string;
132+
protocol: string;
133+
httpMethod: string;
134+
identity: APIGatewayEventIdentity;
135+
messageDirection?: string;
136+
messageId?: string | null;
137+
path: string;
138+
stage: string;
139+
requestId: string;
140+
requestTime?: string;
141+
requestTimeEpoch: number;
142+
resourceId: string;
143+
resourcePath: string;
144+
routeKey?: string;
145+
}
146+
122147
interface ApiResponse {
123148
statusCode: number;
124149
headers: { [name: string]: string | boolean };

0 commit comments

Comments
 (0)