@travetto/web-aws-lambda 7.1.4 → 8.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +6 -6
- package/src/util.ts +12 -13
- package/support/cli.pack_lambda.ts +6 -8
- package/support/test/dispatcher.ts +9 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/web-aws-lambda",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0-alpha.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Web APIs entry point support for AWS Lambdas.",
|
|
6
6
|
"keywords": [
|
|
@@ -26,13 +26,13 @@
|
|
|
26
26
|
"directory": "module/web-aws-lambda"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@travetto/web": "^
|
|
30
|
-
"@types/aws-lambda": "^8.10.
|
|
29
|
+
"@travetto/web": "^8.0.0-alpha.1",
|
|
30
|
+
"@types/aws-lambda": "^8.10.161"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@travetto/cli": "^
|
|
34
|
-
"@travetto/pack": "^
|
|
35
|
-
"@travetto/test": "^
|
|
33
|
+
"@travetto/cli": "^8.0.0-alpha.1",
|
|
34
|
+
"@travetto/pack": "^8.0.0-alpha.1",
|
|
35
|
+
"@travetto/test": "^8.0.0-alpha.1"
|
|
36
36
|
},
|
|
37
37
|
"peerDependenciesMeta": {
|
|
38
38
|
"@travetto/test": {
|
package/src/util.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { buffer } from 'node:stream/consumers';
|
|
2
|
-
|
|
3
1
|
import type { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda';
|
|
4
2
|
|
|
5
|
-
import { castTo } from '@travetto/runtime';
|
|
3
|
+
import { BinaryUtil, castTo, CodecUtil, type BinaryArray } from '@travetto/runtime';
|
|
6
4
|
import { WebBodyUtil, WebCommonUtil, WebRequest, WebResponse } from '@travetto/web';
|
|
7
5
|
|
|
8
6
|
export class AwsLambdaWebUtil {
|
|
@@ -12,7 +10,10 @@ export class AwsLambdaWebUtil {
|
|
|
12
10
|
*/
|
|
13
11
|
static toWebRequest(event: APIGatewayProxyEvent): WebRequest {
|
|
14
12
|
// Build request
|
|
15
|
-
const body = event.body ?
|
|
13
|
+
const body = !event.body ? undefined :
|
|
14
|
+
event.isBase64Encoded ?
|
|
15
|
+
CodecUtil.fromBase64String(event.body) :
|
|
16
|
+
CodecUtil.fromUTF8String(event.body);
|
|
16
17
|
|
|
17
18
|
return new WebRequest({
|
|
18
19
|
context: {
|
|
@@ -25,7 +26,7 @@ export class AwsLambdaWebUtil {
|
|
|
25
26
|
path: event.path,
|
|
26
27
|
},
|
|
27
28
|
headers: { ...event.headers, ...event.multiValueHeaders },
|
|
28
|
-
body: WebBodyUtil.
|
|
29
|
+
body: WebBodyUtil.markRawBinary(body)
|
|
29
30
|
});
|
|
30
31
|
}
|
|
31
32
|
|
|
@@ -37,13 +38,11 @@ export class AwsLambdaWebUtil {
|
|
|
37
38
|
context: response.context,
|
|
38
39
|
...WebBodyUtil.toBinaryMessage(response)
|
|
39
40
|
});
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
const isBase64Encoded = !!output.length && base64Encoded;
|
|
41
|
+
const output: BinaryArray = binaryResponse.body ?
|
|
42
|
+
await BinaryUtil.toBinaryArray(binaryResponse.body) :
|
|
43
|
+
BinaryUtil.makeBinaryArray(0);
|
|
44
|
+
|
|
45
|
+
const isBase64Encoded = !!output.byteLength && base64Encoded;
|
|
47
46
|
const headers: Record<string, string> = {};
|
|
48
47
|
const multiValueHeaders: Record<string, string[]> = {};
|
|
49
48
|
|
|
@@ -58,7 +57,7 @@ export class AwsLambdaWebUtil {
|
|
|
58
57
|
return {
|
|
59
58
|
statusCode: WebCommonUtil.getStatusCode(binaryResponse),
|
|
60
59
|
isBase64Encoded,
|
|
61
|
-
body:
|
|
60
|
+
body: isBase64Encoded ? CodecUtil.toBase64String(output) : CodecUtil.toUTF8String(output),
|
|
62
61
|
headers,
|
|
63
62
|
multiValueHeaders,
|
|
64
63
|
};
|
|
@@ -5,21 +5,19 @@ import { BasePackCommand, type PackOperationShape } from '@travetto/pack/support
|
|
|
5
5
|
/**
|
|
6
6
|
* Standard lambda support for pack
|
|
7
7
|
*/
|
|
8
|
-
@CliCommand(
|
|
8
|
+
@CliCommand()
|
|
9
9
|
export class PackLambdaCommand extends BasePackCommand {
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
finalize(forHelp?: boolean): void {
|
|
12
|
+
if (forHelp) {
|
|
13
|
+
this.output = undefined!;
|
|
14
|
+
this.entryPoint = undefined!;
|
|
15
|
+
}
|
|
12
16
|
this.entryPoint ??= '@travetto/web-aws-lambda/support/entry.handler.ts';
|
|
13
17
|
this.output ??= CliUtil.getSimpleModuleName('<module>.zip', this.module);
|
|
14
18
|
this.mainScripts = false;
|
|
15
19
|
}
|
|
16
20
|
|
|
17
|
-
preHelp(): void {
|
|
18
|
-
this.output = undefined!;
|
|
19
|
-
this.entryPoint = undefined!;
|
|
20
|
-
this.preMain();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
21
|
getOperations(): PackOperationShape<this>[] {
|
|
24
22
|
return [
|
|
25
23
|
...super.getOperations(),
|
|
@@ -2,7 +2,7 @@ import type { APIGatewayProxyEvent, Context } from 'aws-lambda';
|
|
|
2
2
|
|
|
3
3
|
import { Inject, Injectable } from '@travetto/di';
|
|
4
4
|
import { type WebDispatcher, type WebFilterContext, type WebRequest, WebResponse } from '@travetto/web';
|
|
5
|
-
import {
|
|
5
|
+
import { RuntimeError, asFull, BinaryUtil, castTo, CodecUtil, type BinaryArray } from '@travetto/runtime';
|
|
6
6
|
|
|
7
7
|
import { WebTestDispatchUtil } from '@travetto/web/support/test/dispatch-util.ts';
|
|
8
8
|
|
|
@@ -11,15 +11,15 @@ import type { AwsLambdaWebHandler } from '../../src/handler.ts';
|
|
|
11
11
|
/**
|
|
12
12
|
* Create an api gateway event given a web request
|
|
13
13
|
*/
|
|
14
|
-
function toLambdaEvent(request: WebRequest): APIGatewayProxyEvent {
|
|
14
|
+
function toLambdaEvent(request: WebRequest<BinaryArray>): APIGatewayProxyEvent {
|
|
15
15
|
const body = request.body;
|
|
16
16
|
const headers: Record<string, string> = {};
|
|
17
17
|
const multiValueHeaders: Record<string, string[]> = {};
|
|
18
18
|
const queryStringParameters: Record<string, string> = {};
|
|
19
19
|
const multiValueQueryStringParameters: Record<string, string[]> = {};
|
|
20
20
|
|
|
21
|
-
if (
|
|
22
|
-
throw new
|
|
21
|
+
if (body && !BinaryUtil.isBinaryArray(body)) {
|
|
22
|
+
throw new RuntimeError('Unsupported request type, only buffer bodies supported');
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
request.headers.forEach((v, k) => {
|
|
@@ -46,7 +46,7 @@ function toLambdaEvent(request: WebRequest): APIGatewayProxyEvent {
|
|
|
46
46
|
headers,
|
|
47
47
|
multiValueHeaders,
|
|
48
48
|
isBase64Encoded: true,
|
|
49
|
-
body: body
|
|
49
|
+
body: request.body ? CodecUtil.toBase64String(request.body) : null,
|
|
50
50
|
requestContext: castTo({
|
|
51
51
|
identity: castTo({ sourceIp: '127.0.0.1' }),
|
|
52
52
|
}),
|
|
@@ -63,13 +63,14 @@ export class LocalAwsLambdaWebDispatcher implements WebDispatcher {
|
|
|
63
63
|
app: AwsLambdaWebHandler;
|
|
64
64
|
|
|
65
65
|
async dispatch({ request }: WebFilterContext): Promise<WebResponse> {
|
|
66
|
-
const event = toLambdaEvent(await WebTestDispatchUtil.applyRequestBody(request));
|
|
67
|
-
|
|
66
|
+
const event = toLambdaEvent(await WebTestDispatchUtil.applyRequestBody(request, true));
|
|
68
67
|
const response = await this.app.handle(event, asFull<Context>({}));
|
|
69
68
|
|
|
70
69
|
return WebTestDispatchUtil.finalizeResponseBody(
|
|
71
70
|
new WebResponse<unknown>({
|
|
72
|
-
body:
|
|
71
|
+
body: response.isBase64Encoded ?
|
|
72
|
+
CodecUtil.fromBase64String(response.body) :
|
|
73
|
+
CodecUtil.fromUTF8String(response.body),
|
|
73
74
|
headers: { ...response.headers ?? {}, ...response.multiValueHeaders ?? {} },
|
|
74
75
|
context: {
|
|
75
76
|
httpStatusCode: response.statusCode
|