@stone-js/aws-lambda-http-adapter 0.3.1 → 0.8.0

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.
@@ -0,0 +1,21 @@
1
+ import { ClassType, BlueprintContext, IBlueprint, MetaMiddleware, NextMiddleware } from '@stone-js/core';
2
+ /**
3
+ * Middleware to dynamically set response resolver for adapter.
4
+ *
5
+ * @param context - The configuration context containing modules and blueprint.
6
+ * @param next - The next pipeline function to continue processing.
7
+ * @returns The updated blueprint or a promise resolving to it.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * SetAwsLambdaHttpResponseResolverMiddleware(context, next)
12
+ * ```
13
+ */
14
+ export declare const SetAwsLambdaHttpResponseResolverMiddleware: (context: BlueprintContext<IBlueprint, ClassType>, next: NextMiddleware<BlueprintContext<IBlueprint, ClassType>, IBlueprint>) => Promise<IBlueprint>;
15
+ /**
16
+ * Configuration for adapter processing middleware.
17
+ *
18
+ * This array defines a list of middleware pipes, each with a `pipe` function and a `priority`.
19
+ * These pipes are executed in the order of their priority values, with lower values running first.
20
+ */
21
+ export declare const metaAdapterBlueprintMiddleware: Array<MetaMiddleware<BlueprintContext<IBlueprint, ClassType>, IBlueprint>>;
@@ -0,0 +1,78 @@
1
+ import { IBlueprint, NextMiddleware, type MetaMiddleware } from '@stone-js/core';
2
+ import { AwsLambdaHttpAdapterContext, AwsLambdaHttpAdapterResponseBuilder } from '../declarations';
3
+ /**
4
+ * Class representing a BodyEventMiddleware.
5
+ *
6
+ * This middleware handles platform-specific messages and transforms them into Stone.js IncomingEvent objects.
7
+ *
8
+ * @author Mr. Stone
9
+ */
10
+ export declare class BodyEventMiddleware {
11
+ /**
12
+ * The blueprint for resolving configuration and dependencies.
13
+ */
14
+ private readonly blueprint;
15
+ /**
16
+ * Create a BodyEventMiddleware.
17
+ *
18
+ * @param {blueprint} options - Options for creating the BodyEventMiddleware.
19
+ */
20
+ constructor({ blueprint }: {
21
+ blueprint: IBlueprint;
22
+ });
23
+ /**
24
+ * Handles the incoming event, processes it, and invokes the next middleware in the pipeline.
25
+ *
26
+ * @param context - The adapter context containing the raw event, execution context, and other data.
27
+ * @param next - The next middleware to be invoked in the pipeline.
28
+ * @returns A promise that resolves to the destination type after processing.
29
+ *
30
+ * @throws {AwsLambdaHttpAdapterError} If required components such as the rawEvent or IncomingEventBuilder are not provided.
31
+ */
32
+ handle(context: AwsLambdaHttpAdapterContext, next: NextMiddleware<AwsLambdaHttpAdapterContext, AwsLambdaHttpAdapterResponseBuilder>): Promise<AwsLambdaHttpAdapterResponseBuilder>;
33
+ /**
34
+ * Extract a spoofed HTTP method from a parsed body, supporting both JSON objects and
35
+ * urlencoded bodies (whose fields live on a `URLSearchParams`, not as own properties).
36
+ *
37
+ * @param body - The parsed body.
38
+ * @returns The spoofed method, or undefined.
39
+ */
40
+ private extractSpoofedMethod;
41
+ /**
42
+ * Convert the raw event into a Node.js IncomingMessage.
43
+ *
44
+ * @param rawEvent - The raw event from the platform.
45
+ * @returns The converted IncomingMessage.
46
+ */
47
+ private toNodeMessage;
48
+ /**
49
+ * Extract and parse the body from the message.
50
+ *
51
+ * @param message - The incoming HTTP message.
52
+ * @returns A Promise resolving to the parsed body.
53
+ * @throws {AwsLambdaHttpAdapterError} If the body parsing fails or is invalid.
54
+ */
55
+ private getBody;
56
+ /**
57
+ * Decode the request body into a Buffer, honouring base64 encoding.
58
+ *
59
+ * @param rawEvent - The raw event containing the body.
60
+ * @param encoding - The charset for a plain-text (non-base64) body.
61
+ * @returns The body as a Buffer.
62
+ */
63
+ private getRawBuffer;
64
+ /**
65
+ * Parse the body content based on the specified type and encoding.
66
+ *
67
+ * @param type - The content type of the body.
68
+ * @param buffer - The raw body content as a Buffer.
69
+ * @param encoding - The encoding of the body content.
70
+ * @returns The parsed body content as an object, string, or Buffer.
71
+ * @throws {AwsLambdaHttpAdapterError} If parsing fails.
72
+ */
73
+ private parseBodyContent;
74
+ }
75
+ /**
76
+ * Meta Middleware for processing the request body.
77
+ */
78
+ export declare const MetaBodyEventMiddleware: MetaMiddleware<any, any>;
@@ -0,0 +1,42 @@
1
+ import { IBlueprint, NextMiddleware, type MetaMiddleware } from '@stone-js/core';
2
+ import { AwsLambdaHttpAdapterContext, AwsLambdaHttpAdapterResponseBuilder } from '../declarations';
3
+ /**
4
+ * Class representing a FilesEventMiddleware.
5
+ *
6
+ * @author Mr. Stone <evensstone@gmail.com>
7
+ */
8
+ export declare class FilesEventMiddleware {
9
+ /**
10
+ * The blueprint for resolving configuration and dependencies.
11
+ */
12
+ private readonly blueprint;
13
+ /**
14
+ * Create a FilesEventMiddleware.
15
+ *
16
+ * @param {blueprint} options - Options for creating the FilesEventMiddleware.
17
+ */
18
+ constructor({ blueprint }: {
19
+ blueprint: IBlueprint;
20
+ });
21
+ /**
22
+ * Handles the incoming event, processes it, and invokes the next middleware in the pipeline.
23
+ *
24
+ * @param context - The adapter context containing the raw event, execution context, and other data.
25
+ * @param next - The next middleware to be invoked in the pipeline.
26
+ * @returns A promise that resolves to the destination type after processing.
27
+ *
28
+ * @throws {AwsLambdaHttpAdapterError} If required components such as the rawEvent or IncomingEventBuilder are not provided.
29
+ */
30
+ handle(context: AwsLambdaHttpAdapterContext, next: NextMiddleware<AwsLambdaHttpAdapterContext, AwsLambdaHttpAdapterResponseBuilder>): Promise<AwsLambdaHttpAdapterResponseBuilder>;
31
+ /**
32
+ * Normalize the incoming event to an IncomingMessage.
33
+ *
34
+ * @param rawEvent - The raw event to be normalized.
35
+ * @returns The normalized event.
36
+ */
37
+ private normalizeEvent;
38
+ }
39
+ /**
40
+ * Meta Middleware for processing files uploads.
41
+ */
42
+ export declare const MetaFilesEventMiddleware: MetaMiddleware<any, any>;
@@ -0,0 +1,97 @@
1
+ import { IBlueprint, NextMiddleware, type MetaMiddleware } from '@stone-js/core';
2
+ import { AwsLambdaHttpAdapterContext, AwsLambdaHttpAdapterResponseBuilder } from '../declarations';
3
+ /**
4
+ * Middleware for handling incoming events and transforming them into Stone.js events.
5
+ *
6
+ * It first normalizes the raw AWS event (API Gateway v1/v2, ALB, Function URLs) into a single
7
+ * canonical shape, then extracts URL, IP addresses, headers, cookies, query and the raw body,
8
+ * so the pipeline never has to reason about which trigger fired. The untouched request body is
9
+ * always exposed as `metadata.rawBody` — even when no body-parsing middleware is installed — so
10
+ * consumers can read the original payload (e.g. to verify a webhook signature).
11
+ */
12
+ export declare class IncomingEventMiddleware {
13
+ /**
14
+ * The blueprint for resolving configuration and dependencies.
15
+ */
16
+ private readonly blueprint;
17
+ /**
18
+ * Create an IncomingEventMiddleware instance.
19
+ *
20
+ * @param options - Options containing the blueprint for resolving configuration and dependencies.
21
+ */
22
+ constructor({ blueprint }: {
23
+ blueprint: IBlueprint;
24
+ });
25
+ /**
26
+ * Handles the incoming event, processes it, and invokes the next middleware in the pipeline.
27
+ *
28
+ * @param context - The adapter context containing the raw event, execution context, and other data.
29
+ * @param next - The next middleware to be invoked in the pipeline.
30
+ * @returns A promise that resolves to the processed context.
31
+ * @throws {AwsLambdaHttpAdapterError} If required components are missing in the context.
32
+ */
33
+ handle(context: AwsLambdaHttpAdapterContext, next: NextMiddleware<AwsLambdaHttpAdapterContext, AwsLambdaHttpAdapterResponseBuilder>): Promise<AwsLambdaHttpAdapterResponseBuilder>;
34
+ /**
35
+ * Create the IncomingEventSource from the context.
36
+ *
37
+ * @param context - The adapter context containing the raw event, execution context, and other data.
38
+ * @returns The Incoming Event Source.
39
+ */
40
+ private getSource;
41
+ /**
42
+ * Extracts proxy-related options from the blueprint.
43
+ *
44
+ * @returns Proxy options.
45
+ */
46
+ private getProxyOptions;
47
+ /**
48
+ * Retrieves cookie-related options from the blueprint.
49
+ *
50
+ * @returns Cookie options.
51
+ */
52
+ private getCookieOptions;
53
+ /**
54
+ * Retrieves the cookie secret from the blueprint.
55
+ *
56
+ * @returns The cookie secret string.
57
+ */
58
+ private getCookieSecret;
59
+ /**
60
+ * Extracts and parses the URL (including the query string) from the normalized event.
61
+ *
62
+ * @param event - The normalized HTTP event.
63
+ * @param options - Proxy options.
64
+ * @returns The parsed URL object.
65
+ */
66
+ private extractUrl;
67
+ /**
68
+ * Extracts a list of IP addresses from the normalized event.
69
+ *
70
+ * @param event - The normalized HTTP event.
71
+ * @param options - Proxy options.
72
+ * @returns An array of IP addresses.
73
+ */
74
+ private extractIpAddresses;
75
+ /**
76
+ * Converts the normalized event to a minimal Node.js IncomingMessage for `proxy-addr`.
77
+ *
78
+ * All standard forwarding headers are forwarded (not just `x-forwarded-for`) so proxy-addr can
79
+ * honour the deployment's trust configuration.
80
+ *
81
+ * @param event - The normalized HTTP event.
82
+ * @returns The converted IncomingMessage.
83
+ */
84
+ private toNodeMessage;
85
+ /**
86
+ * Determines the protocol from the normalized event.
87
+ *
88
+ * @param event - The normalized HTTP event.
89
+ * @param options - Proxy options.
90
+ * @returns The protocol string.
91
+ */
92
+ private getProtocol;
93
+ }
94
+ /**
95
+ * Meta Middleware for processing incoming events.
96
+ */
97
+ export declare const MetaIncomingEventMiddleware: MetaMiddleware<any, any>;
@@ -0,0 +1,23 @@
1
+ import { NextMiddleware, type MetaMiddleware } from '@stone-js/core';
2
+ import { AwsLambdaHttpAdapterContext, AwsLambdaHttpAdapterResponseBuilder } from '../declarations';
3
+ /**
4
+ * Middleware for handling server responses and transforming them into the appropriate HTTP responses.
5
+ *
6
+ * This middleware processes outgoing responses and attaches the necessary headers, status codes,
7
+ * and body content to the HTTP response.
8
+ */
9
+ export declare class ServerResponseMiddleware {
10
+ /**
11
+ * Handles the outgoing response, processes it, and invokes the next middleware in the pipeline.
12
+ *
13
+ * @param context - The adapter context containing the raw event, execution context, and other data.
14
+ * @param next - The next middleware to be invoked in the pipeline.
15
+ * @returns A promise resolving to the rawResponseBuilder.
16
+ * @throws {AwsLambdaHttpAdapterError} If required components are missing in the context.
17
+ */
18
+ handle(context: AwsLambdaHttpAdapterContext, next: NextMiddleware<AwsLambdaHttpAdapterContext, AwsLambdaHttpAdapterResponseBuilder>): Promise<AwsLambdaHttpAdapterResponseBuilder>;
19
+ }
20
+ /**
21
+ * Meta Middleware for processing server responses.
22
+ */
23
+ export declare const MetaServerResponseMiddleware: MetaMiddleware<any, any>;
@@ -0,0 +1,41 @@
1
+ import { AwsLambdaContext, AwsLambdaHttpEvent, RawHttpResponse } from '../declarations';
2
+ import { AdapterConfig, AppConfig, StoneBlueprint } from '@stone-js/core';
3
+ import { HttpConfig, IncomingHttpEvent, IncomingHttpEventOptions, OutgoingHttpResponse } from '@stone-js/http-core';
4
+ /**
5
+ * Configuration interface for the AWS Lambda Http Adapter.
6
+ *
7
+ * Extends the `AdapterConfig` interface from the Stone.js framework and provides
8
+ * customizable options specific to the AWS Lambda platform. This includes
9
+ * alias, resolver, middleware, hooks, and various adapter state flags.
10
+ */
11
+ export interface AwsLambdaHttpAdapterAdapterConfig extends AdapterConfig<AwsLambdaHttpEvent, RawHttpResponse, AwsLambdaContext, IncomingHttpEvent, IncomingHttpEventOptions, OutgoingHttpResponse> {
12
+ }
13
+ /**
14
+ * Represents the AwsLambdaHttpAdapterConfig configuration options for the application.
15
+ */
16
+ export interface AwsLambdaHttpAdapterConfig extends Partial<AppConfig<IncomingHttpEvent, OutgoingHttpResponse>> {
17
+ http: Partial<HttpConfig>;
18
+ }
19
+ /**
20
+ * Blueprint interface for the AWS Lambda Http Adapter.
21
+ *
22
+ * This interface extends `StoneBlueprint` and defines the structure of the
23
+ * AWS Lambda Http adapter blueprint used in the Stone.js framework. It includes
24
+ * a `stone` object with an array of `AwsLambdaHttpAdapterConfig` items.
25
+ */
26
+ export interface AwsLambdaHttpAdapterBlueprint extends StoneBlueprint<IncomingHttpEvent, OutgoingHttpResponse> {
27
+ /**
28
+ * Application-level settings, including environment, middleware, logging, and service registration.
29
+ */
30
+ stone: AwsLambdaHttpAdapterConfig;
31
+ }
32
+ /**
33
+ * Default blueprint configuration for the AWS Lambda Http Adapter.
34
+ *
35
+ * This blueprint defines the initial configuration for the AWS Lambda Http adapter
36
+ * within the Stone.js framework. It includes:
37
+ * - An alias for the AWS Lambda platform (`AWS_LAMBDA_HTTP_PLATFORM`).
38
+ * - A default resolver function (currently a placeholder).
39
+ * - Middleware, hooks, and state flags (`current`, `default`, `preferred`).
40
+ */
41
+ export declare const awsLambdaHttpAdapterBlueprint: AwsLambdaHttpAdapterBlueprint;
@@ -0,0 +1,10 @@
1
+ import { AdapterResolver } from '@stone-js/core';
2
+ /**
3
+ * Adapter resolver for AWS Lambda HTTP adapter.
4
+ *
5
+ * Creates and configures an `AWSLambdaHttpAdapter` for handling HTTP events in AWS Lambda.
6
+ *
7
+ * @param blueprint - The `IBlueprint` providing configuration and dependencies.
8
+ * @returns An `AWSLambdaHttpAdapter` instance.
9
+ */
10
+ export declare const awsLambdaHttpAdapterResolver: AdapterResolver;
package/package.json CHANGED
@@ -1,16 +1,17 @@
1
1
  {
2
2
  "name": "@stone-js/aws-lambda-http-adapter",
3
- "version": "0.3.1",
3
+ "version": "0.8.0",
4
4
  "description": "Official AWS Lambda HTTP adapter for Stone.js. Run your Stone.js apps on AWS Lambda behind API Gateway with full Continuum lifecycle support.",
5
5
  "author": "Mr. Stone <evensstone@gmail.com>",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "git+ssh://git@github.com/stone-foundation/stone-js-aws-lambda-http-adapter.git"
9
+ "url": "git+https://github.com/stone-foundation/stone-js-framework.git",
10
+ "directory": "stone-js-aws-lambda-http-adapter"
10
11
  },
11
12
  "homepage": "https://stonejs.dev",
12
13
  "bugs": {
13
- "url": "https://github.com/stone-foundation/stone-js-aws-lambda-http-adapter/issues"
14
+ "url": "https://github.com/stone-foundation/stone-js-framework/issues"
14
15
  },
15
16
  "keywords": [
16
17
  "aws",
@@ -31,6 +32,7 @@
31
32
  "/dist"
32
33
  ],
33
34
  "type": "module",
35
+ "sideEffects": false,
34
36
  "types": "./dist/index.d.ts",
35
37
  "exports": {
36
38
  ".": {
@@ -52,7 +54,7 @@
52
54
  "lint:fix": "ts-standard --fix src tests",
53
55
  "predoc": "rimraf docs",
54
56
  "doc": "typedoc",
55
- "prebuild": "rimraf dist && npm run doc",
57
+ "clean": "rimraf dist",
56
58
  "build": "rollup -c",
57
59
  "test": "vitest run",
58
60
  "test:cvg": "npm run test -- --coverage",
@@ -62,12 +64,13 @@
62
64
  "prepare": "husky"
63
65
  },
64
66
  "peerDependencies": {
65
- "@stone-js/core": "^0.2.1",
66
- "@stone-js/env": "^0.1.2",
67
- "@stone-js/filesystem": "^0.1.2",
68
- "@stone-js/http-core": "^0.1.4"
67
+ "@stone-js/core": "workspace:*",
68
+ "@stone-js/env": "workspace:*",
69
+ "@stone-js/filesystem": "workspace:*",
70
+ "@stone-js/http-core": "workspace:*"
69
71
  },
70
72
  "dependencies": {
73
+ "@stone-js/config": "workspace:*",
71
74
  "accepts": "^1.3.8",
72
75
  "bytes": "^3.1.2",
73
76
  "content-type": "^1.0.5",
@@ -94,8 +97,6 @@
94
97
  "husky": "^9.1.7",
95
98
  "rimraf": "^6.1.0",
96
99
  "rollup": "^4.52.5",
97
- "rollup-plugin-delete": "^3.0.1",
98
- "rollup-plugin-dts": "^6.2.3",
99
100
  "rollup-plugin-node-externals": "^8.1.1",
100
101
  "ts-standard": "^12.0.2",
101
102
  "tslib": "^2.8.1",