@travetto/web-aws-lambda 8.0.0-alpha.9 → 8.0.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/README.md CHANGED
@@ -13,18 +13,25 @@ npm install @travetto/web-aws-lambda
13
13
  yarn add @travetto/web-aws-lambda
14
14
  ```
15
15
 
16
- This module provides an adapter between [Web API](https://github.com/travetto/travetto/tree/main/module/web#readme "Declarative support for creating Web Applications") and [AWS Lambda](https://aws.amazon.com/lambda/). The event-driven invocation model for [Web API](https://github.com/travetto/travetto/tree/main/module/web#readme "Declarative support for creating Web Applications") aligns cleanly with [AWS Lambda](https://aws.amazon.com/lambda/)'s model for event-driven operation.
16
+ This module provides an adapter between [Web API](https://github.com/travetto/travetto/tree/main/module/web#readme "Declarative support for creating Web Applications") and [AWS Lambda](https://aws.amazon.com/lambda/). The event-driven invocation model for [Web API](https://github.com/travetto/travetto/tree/main/module/web#readme "Declarative support for creating Web Applications") aligns cleanly with [AWS Lambda](https://aws.amazon.com/lambda/)'s model for event-driven operation.
17
17
 
18
18
  **NOTE:** The only caveat to consider, is that while the framework supports streams for responses, [AWS Lambda](https://aws.amazon.com/lambda/) does not. Any streaming result will be read and converted into a [Buffer](https://nodejs.org/api/buffer.html) before being sent back.
19
19
 
20
- ## CLI - Packaging Lambdas
20
+ ## CLI - pack:lambda
21
+ Use this command to produce the Lambda-ready archive for deployment.
21
22
 
22
- **Terminal: Invoking a Package Build**
23
+ **Terminal: Help for pack:lambda**
23
24
  ```bash
24
25
  $ trv pack:lambda --help
25
26
 
26
27
  Usage: pack:lambda [options] [args...:string]
27
28
 
29
+ Description:
30
+ Build an AWS Lambda-ready zip package using the pack pipeline.
31
+
32
+ Configures the Lambda entrypoint and emits a compressed deployment artifact
33
+ suitable for direct Lambda upload workflows.
34
+
28
35
  Options:
29
36
  -b, --buildDir <string> Workspace for building (default: "/tmp/<temp-folder>")
30
37
  --clean, --no-clean Clean workspace (default: true)
@@ -43,4 +50,6 @@ Options:
43
50
  -np, --npm-package <string> External NPM Packages (default: [])
44
51
  -m, --module <module> Module to run for
45
52
  --help display help for command
53
+
54
+ Examples:
46
55
  ```
package/__index__.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export * from './src/handler.ts';
2
- export * from './src/util.ts';
2
+ export * from './src/util.ts';
package/package.json CHANGED
@@ -1,38 +1,41 @@
1
1
  {
2
2
  "name": "@travetto/web-aws-lambda",
3
- "version": "8.0.0-alpha.9",
4
- "type": "module",
3
+ "version": "8.0.1",
5
4
  "description": "Web APIs entry point support for AWS Lambdas.",
6
5
  "keywords": [
7
- "web",
8
6
  "aws-lambda",
9
7
  "travetto",
10
- "typescript"
8
+ "typescript",
9
+ "web"
11
10
  ],
12
11
  "homepage": "https://travetto.io",
13
12
  "license": "MIT",
14
13
  "author": {
15
- "email": "travetto.framework@gmail.com",
16
- "name": "Travetto Framework"
14
+ "name": "Travetto Framework",
15
+ "email": "travetto.framework@gmail.com"
16
+ },
17
+ "repository": {
18
+ "url": "git+https://github.com/travetto/travetto.git",
19
+ "directory": "module/web-aws-lambda"
17
20
  },
18
21
  "files": [
19
22
  "__index__.ts",
20
23
  "src",
21
24
  "support"
22
25
  ],
26
+ "type": "module",
23
27
  "main": "__index__.ts",
24
- "repository": {
25
- "url": "git+https://github.com/travetto/travetto.git",
26
- "directory": "module/web-aws-lambda"
28
+ "publishConfig": {
29
+ "access": "public"
27
30
  },
28
31
  "dependencies": {
29
- "@travetto/web": "^8.0.0-alpha.8",
30
- "@types/aws-lambda": "^8.10.161"
32
+ "@travetto/web": "^8.0.1",
33
+ "@types/aws-lambda": "^8.10.163"
31
34
  },
32
35
  "peerDependencies": {
33
- "@travetto/cli": "^8.0.0-alpha.12",
34
- "@travetto/pack": "^8.0.0-alpha.10",
35
- "@travetto/test": "^8.0.0-alpha.7"
36
+ "@travetto/cli": "^8.0.1",
37
+ "@travetto/pack": "^8.0.1",
38
+ "@travetto/test": "^8.0.1"
36
39
  },
37
40
  "peerDependenciesMeta": {
38
41
  "@travetto/test": {
@@ -47,8 +50,5 @@
47
50
  },
48
51
  "travetto": {
49
52
  "displayName": "Web AWS Lambda"
50
- },
51
- "publishConfig": {
52
- "access": "public"
53
53
  }
54
54
  }
package/src/handler.ts CHANGED
@@ -1,16 +1,15 @@
1
1
  import type lambda from 'aws-lambda';
2
2
 
3
- import { Runtime, ConsoleManager } from '@travetto/runtime';
3
+ import { ConfigurationService } from '@travetto/config';
4
4
  import { DependencyRegistryIndex, Inject, Injectable } from '@travetto/di';
5
5
  import { Registry } from '@travetto/registry';
6
- import { ConfigurationService } from '@travetto/config';
6
+ import { ConsoleManager, Runtime } from '@travetto/runtime';
7
7
  import type { StandardWebRouter } from '@travetto/web';
8
8
 
9
9
  import { AwsLambdaWebUtil } from './util.ts';
10
10
 
11
11
  @Injectable()
12
12
  export class AwsLambdaWebHandler {
13
-
14
13
  static inst: AwsLambdaWebHandler;
15
14
 
16
15
  static entryPoint(): (event: lambda.APIGatewayProxyEvent, context: lambda.Context) => Promise<lambda.APIGatewayProxyResult> {
@@ -35,4 +34,4 @@ export class AwsLambdaWebHandler {
35
34
  const response = await this.router.dispatch({ request });
36
35
  return AwsLambdaWebUtil.toLambdaResult(response, event.isBase64Encoded);
37
36
  }
38
- }
37
+ }
package/src/util.ts CHANGED
@@ -1,29 +1,29 @@
1
1
  import type { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda';
2
2
 
3
- import { BinaryUtil, castTo, CodecUtil, type BinaryArray } from '@travetto/runtime';
3
+ import { type BinaryArray, BinaryUtil, CodecUtil, castTo } from '@travetto/runtime';
4
4
  import { WebBodyUtil, WebCommonUtil, WebRequest, WebResponse } from '@travetto/web';
5
5
 
6
6
  export class AwsLambdaWebUtil {
7
-
8
7
  /**
9
8
  * Create a request from an api gateway event
10
9
  */
11
10
  static toWebRequest(event: APIGatewayProxyEvent): WebRequest {
12
11
  // Build request
13
- const body = !event.body ? undefined :
14
- event.isBase64Encoded ?
15
- CodecUtil.fromBase64String(event.body) :
16
- CodecUtil.fromUTF8String(event.body);
12
+ const body = !event.body
13
+ ? undefined
14
+ : event.isBase64Encoded
15
+ ? CodecUtil.fromBase64String(event.body)
16
+ : CodecUtil.fromUTF8String(event.body);
17
17
 
18
18
  return new WebRequest({
19
19
  context: {
20
20
  connection: {
21
21
  httpProtocol: 'http',
22
- ip: event.requestContext.identity?.sourceIp,
22
+ ip: event.requestContext.identity?.sourceIp
23
23
  },
24
24
  httpMethod: castTo(event.httpMethod.toUpperCase()),
25
25
  httpQuery: castTo(event.queryStringParameters!),
26
- path: event.path,
26
+ path: event.path
27
27
  },
28
28
  headers: { ...event.headers, ...event.multiValueHeaders },
29
29
  body: WebBodyUtil.markRawBinary(body)
@@ -38,9 +38,7 @@ export class AwsLambdaWebUtil {
38
38
  context: response.context,
39
39
  ...WebBodyUtil.toBinaryMessage(response)
40
40
  });
41
- const output: BinaryArray = binaryResponse.body ?
42
- await BinaryUtil.toBinaryArray(binaryResponse.body) :
43
- BinaryUtil.makeBinaryArray(0);
41
+ const output: BinaryArray = binaryResponse.body ? await BinaryUtil.toBinaryArray(binaryResponse.body) : BinaryUtil.makeBinaryArray(0);
44
42
 
45
43
  const isBase64Encoded = !!output.byteLength && base64Encoded;
46
44
  const headers: Record<string, string> = {};
@@ -59,7 +57,7 @@ export class AwsLambdaWebUtil {
59
57
  isBase64Encoded,
60
58
  body: isBase64Encoded ? CodecUtil.toBase64String(output) : CodecUtil.toUTF8String(output),
61
59
  headers,
62
- multiValueHeaders,
60
+ multiValueHeaders
63
61
  };
64
62
  }
65
- }
63
+ }
@@ -1,13 +1,16 @@
1
1
  import { CliCommand, CliUtil } from '@travetto/cli';
2
+
2
3
  import { PackOperation } from '@travetto/pack/support/bin/operation.ts';
3
4
  import { BasePackCommand, type PackOperationShape } from '@travetto/pack/support/pack.base.ts';
4
5
 
5
6
  /**
6
- * Standard lambda support for pack
7
+ * Build an AWS Lambda-ready zip package using the pack pipeline.
8
+ *
9
+ * Configures the Lambda entrypoint and emits a compressed deployment artifact
10
+ * suitable for direct Lambda upload workflows.
7
11
  */
8
12
  @CliCommand()
9
13
  export class PackLambdaCommand extends BasePackCommand {
10
-
11
14
  constructor() {
12
15
  super();
13
16
  this.entryPoint = '@travetto/web-aws-lambda/support/entry.handler.ts';
@@ -22,9 +25,6 @@ export class PackLambdaCommand extends BasePackCommand {
22
25
  }
23
26
 
24
27
  getOperations(): PackOperationShape<this>[] {
25
- return [
26
- ...super.getOperations(),
27
- PackOperation.compress
28
- ];
28
+ return [...super.getOperations(), PackOperation.compress];
29
29
  }
30
- }
30
+ }
@@ -1,3 +1,3 @@
1
1
  // @trv-no-transform
2
2
  import { AwsLambdaWebHandler } from '../src/handler.ts';
3
- export const handler = AwsLambdaWebHandler.entryPoint();
3
+ export const handler = AwsLambdaWebHandler.entryPoint();
@@ -1,8 +1,8 @@
1
1
  import type { APIGatewayProxyEvent, Context } from 'aws-lambda';
2
2
 
3
3
  import { Inject, Injectable } from '@travetto/di';
4
+ import { asFull, type BinaryArray, BinaryUtil, CodecUtil, castTo, RuntimeError } from '@travetto/runtime';
4
5
  import { type WebDispatcher, type WebFilterContext, type WebRequest, WebResponse } from '@travetto/web';
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
 
@@ -48,8 +48,8 @@ function toLambdaEvent(request: WebRequest<BinaryArray>): APIGatewayProxyEvent {
48
48
  isBase64Encoded: true,
49
49
  body: request.body ? CodecUtil.toBase64String(request.body) : null,
50
50
  requestContext: castTo({
51
- identity: castTo({ sourceIp: '127.0.0.1' }),
52
- }),
51
+ identity: castTo({ sourceIp: '127.0.0.1' })
52
+ })
53
53
  };
54
54
  }
55
55
 
@@ -58,7 +58,6 @@ function toLambdaEvent(request: WebRequest<BinaryArray>): APIGatewayProxyEvent {
58
58
  */
59
59
  @Injectable()
60
60
  export class LocalAwsLambdaWebDispatcher implements WebDispatcher {
61
-
62
61
  @Inject()
63
62
  app: AwsLambdaWebHandler;
64
63
 
@@ -68,10 +67,8 @@ export class LocalAwsLambdaWebDispatcher implements WebDispatcher {
68
67
 
69
68
  return WebTestDispatchUtil.finalizeResponseBody(
70
69
  new WebResponse<unknown>({
71
- body: response.isBase64Encoded ?
72
- CodecUtil.fromBase64String(response.body) :
73
- CodecUtil.fromUTF8String(response.body),
74
- headers: { ...response.headers ?? {}, ...response.multiValueHeaders ?? {} },
70
+ body: response.isBase64Encoded ? CodecUtil.fromBase64String(response.body) : CodecUtil.fromUTF8String(response.body),
71
+ headers: { ...(response.headers ?? {}), ...(response.multiValueHeaders ?? {}) },
75
72
  context: {
76
73
  httpStatusCode: response.statusCode
77
74
  }
@@ -79,4 +76,4 @@ export class LocalAwsLambdaWebDispatcher implements WebDispatcher {
79
76
  true
80
77
  );
81
78
  }
82
- }
79
+ }