@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.
- package/dist/AWSLambdaHttpAdapter.d.ts +85 -0
- package/dist/AwsLambdaHttpErrorHandler.d.ts +28 -0
- package/dist/RawHttpResponseWrapper.d.ts +69 -0
- package/dist/browser/decorators/AwsLambdaHttp.d.ts +38 -0
- package/dist/browser/options/NodeHttpAdapterBlueprint.d.ts +13 -0
- package/dist/constants.d.ts +8 -0
- package/dist/declarations.d.ts +124 -0
- package/dist/decorators/AwsLambdaHttp.d.ts +34 -0
- package/dist/errors/AwsLambdaHttpAdapterError.d.ts +7 -0
- package/dist/event-normalizer.d.ts +110 -0
- package/dist/index.d.ts +15 -668
- package/dist/index.js +473 -414
- package/dist/middleware/BlueprintMiddleware.d.ts +21 -0
- package/dist/middleware/BodyEventMiddleware.d.ts +78 -0
- package/dist/middleware/FilesEventMiddleware.d.ts +42 -0
- package/dist/middleware/IncomingEventMiddleware.d.ts +97 -0
- package/dist/middleware/ServerResponseMiddleware.d.ts +23 -0
- package/dist/options/AwsLambdaHttpAdapterBlueprint.d.ts +41 -0
- package/dist/resolvers.d.ts +10 -0
- package/package.json +11 -10
package/dist/index.d.ts
CHANGED
|
@@ -1,668 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
*
|
|
17
|
-
* This method accepts partial response options, allowing the user to configure
|
|
18
|
-
* only the required fields. It initializes the wrapper with these options.
|
|
19
|
-
*
|
|
20
|
-
* @param options - Partial options to configure the HTTP response.
|
|
21
|
-
* @returns A new instance of `RawHttpResponseWrapper`.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```typescript
|
|
25
|
-
* const responseWrapper = RawHttpResponseWrapper.create({
|
|
26
|
-
* statusCode: 200,
|
|
27
|
-
* body: { message: 'Success' },
|
|
28
|
-
* headers: { 'Content-Type': 'application/json' }
|
|
29
|
-
* });
|
|
30
|
-
*
|
|
31
|
-
* const response = responseWrapper.respond();
|
|
32
|
-
* console.log(response); // { statusCode: 200, body: '{"message":"Success"}', headers: { 'Content-Type': 'application/json' } }
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
static create(options: Partial<RawHttpResponseOptions>): RawHttpResponseWrapper;
|
|
36
|
-
/**
|
|
37
|
-
* Constructs an instance of `RawHttpResponseWrapper`.
|
|
38
|
-
*
|
|
39
|
-
* This constructor is private and should not be called directly.
|
|
40
|
-
* Use the `create` method to initialize an instance.
|
|
41
|
-
*
|
|
42
|
-
* @param options - Partial options for configuring the HTTP response.
|
|
43
|
-
*/
|
|
44
|
-
private constructor();
|
|
45
|
-
/**
|
|
46
|
-
* Constructs and returns the raw HTTP response.
|
|
47
|
-
*
|
|
48
|
-
* The `respond` method generates a `RawHttpResponse` object based on the
|
|
49
|
-
* provided options. If any required fields are missing, it assigns default values:
|
|
50
|
-
* - `statusCode`: Defaults to `500`.
|
|
51
|
-
*
|
|
52
|
-
* @returns A `RawHttpResponse` object.
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* ```typescript
|
|
56
|
-
* const responseWrapper = RawHttpResponseWrapper.create({ body: 'Hello, world!', statusCode: 200 });
|
|
57
|
-
* const response = responseWrapper.respond();
|
|
58
|
-
* console.log(response); // { statusCode: 500, statusMessage: '', body: 'Hello, world!', headers: undefined }
|
|
59
|
-
* ```
|
|
60
|
-
*/
|
|
61
|
-
respond(): RawHttpResponse;
|
|
62
|
-
/**
|
|
63
|
-
* Normalizes the headers to a consistent format.
|
|
64
|
-
*
|
|
65
|
-
* Converts Headers or Record<string, string> to a normalized Record<string, string>
|
|
66
|
-
* with all keys in lowercase.
|
|
67
|
-
*
|
|
68
|
-
* @param headers - The headers to normalize.
|
|
69
|
-
* @returns A normalized record of headers.
|
|
70
|
-
*/
|
|
71
|
-
private normalizeHeaders;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Represents a raw HTTP response, extending from `RawHttpResponseOptions`.
|
|
76
|
-
*/
|
|
77
|
-
type RawHttpResponse = RawHttpResponseOptions;
|
|
78
|
-
/**
|
|
79
|
-
* Represents the AWS Lambda execution context as a key-value pair.
|
|
80
|
-
*/
|
|
81
|
-
type AwsLambdaContext = Record<string, unknown>;
|
|
82
|
-
/**
|
|
83
|
-
* Represents an AWS Lambda event handler function.
|
|
84
|
-
*
|
|
85
|
-
* @template RawResponseType - The type of the response returned by the handler.
|
|
86
|
-
* @param rawEvent - The raw event received by the AWS Lambda function.
|
|
87
|
-
* @param context - The AWS Lambda execution context.
|
|
88
|
-
* @returns A promise resolving to the response of type `RawResponseType`.
|
|
89
|
-
*/
|
|
90
|
-
type AwsLambdaEventHandlerFunction<RawResponseType = RawHttpResponse> = (rawEvent: AwsLambdaHttpEvent, context: AwsLambdaContext) => Promise<RawResponseType>;
|
|
91
|
-
/**
|
|
92
|
-
* Represents the response builder for the AWS Lambda http Adapter.
|
|
93
|
-
*/
|
|
94
|
-
type AwsLambdaHttpAdapterResponseBuilder = IAdapterEventBuilder<RawHttpResponseOptions, RawHttpResponseWrapper>;
|
|
95
|
-
/**
|
|
96
|
-
* Represents the structure of an AWS Lambda HTTP event.
|
|
97
|
-
*
|
|
98
|
-
* This interface defines the standard properties of an HTTP event in AWS Lambda,
|
|
99
|
-
* including headers, query parameters, the request context, and other metadata.
|
|
100
|
-
*/
|
|
101
|
-
interface AwsLambdaHttpEvent extends Record<string, unknown> {
|
|
102
|
-
/**
|
|
103
|
-
* The path of the HTTP request.
|
|
104
|
-
*/
|
|
105
|
-
path?: string;
|
|
106
|
-
/**
|
|
107
|
-
* The body of the HTTP request.
|
|
108
|
-
*/
|
|
109
|
-
body?: unknown;
|
|
110
|
-
/**
|
|
111
|
-
* The encoding format of the body, such as `base64`.
|
|
112
|
-
*/
|
|
113
|
-
encoding?: string;
|
|
114
|
-
/**
|
|
115
|
-
* The raw path of the HTTP request, as sent by the client.
|
|
116
|
-
*/
|
|
117
|
-
rawPath?: string;
|
|
118
|
-
/**
|
|
119
|
-
* Indicates whether the request body is base64-encoded.
|
|
120
|
-
*/
|
|
121
|
-
isBase64Encoded?: boolean;
|
|
122
|
-
/**
|
|
123
|
-
* The headers of the HTTP request as key-value pairs.
|
|
124
|
-
*/
|
|
125
|
-
headers: Record<string, string>;
|
|
126
|
-
/**
|
|
127
|
-
* The HTTP method of the request (e.g., `GET`, `POST`).
|
|
128
|
-
*/
|
|
129
|
-
httpMethod?: string;
|
|
130
|
-
/**
|
|
131
|
-
* The query string parameters included in the request.
|
|
132
|
-
*/
|
|
133
|
-
queryStringParameters?: Record<string, string>;
|
|
134
|
-
/**
|
|
135
|
-
* The context of the request, including identity and HTTP metadata.
|
|
136
|
-
*/
|
|
137
|
-
requestContext?: {
|
|
138
|
-
identity?: {
|
|
139
|
-
sourceIp?: string;
|
|
140
|
-
};
|
|
141
|
-
httpMethod?: string;
|
|
142
|
-
http?: {
|
|
143
|
-
method?: string;
|
|
144
|
-
sourceIp?: string;
|
|
145
|
-
};
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Represents the context for the AWS Lambda HTTP Adapter.
|
|
150
|
-
*
|
|
151
|
-
* This interface extends `AdapterContext` and includes additional properties specific
|
|
152
|
-
* to HTTP events in AWS Lambda.
|
|
153
|
-
*/
|
|
154
|
-
interface AwsLambdaHttpAdapterContext extends AdapterContext<AwsLambdaHttpEvent, RawHttpResponse, AwsLambdaContext, IncomingHttpEvent, IncomingHttpEventOptions, OutgoingHttpResponse> {
|
|
155
|
-
/**
|
|
156
|
-
* The raw HTTP response associated with the current context.
|
|
157
|
-
*/
|
|
158
|
-
rawResponse: RawHttpResponse;
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Represents options for configuring a raw HTTP response.
|
|
162
|
-
*
|
|
163
|
-
* Extends the `RawResponseOptions` interface to include additional properties
|
|
164
|
-
* for managing response content, headers, status codes, and streaming files.
|
|
165
|
-
*/
|
|
166
|
-
interface RawHttpResponseOptions extends RawResponseOptions {
|
|
167
|
-
/**
|
|
168
|
-
* The body of the HTTP response. Can be of any type, including strings, objects, or buffers.
|
|
169
|
-
*/
|
|
170
|
-
body?: unknown;
|
|
171
|
-
/**
|
|
172
|
-
* The HTTP status code of the response (e.g., `200`, `404`).
|
|
173
|
-
*/
|
|
174
|
-
statusCode: number;
|
|
175
|
-
/**
|
|
176
|
-
* The status message accompanying the HTTP status code (e.g., `OK`, `Not Found`).
|
|
177
|
-
*/
|
|
178
|
-
statusMessage?: string;
|
|
179
|
-
/**
|
|
180
|
-
* Headers to include in the HTTP response.
|
|
181
|
-
* Can be provided as key-value pairs.
|
|
182
|
-
*/
|
|
183
|
-
headers?: Record<string, string>;
|
|
184
|
-
/**
|
|
185
|
-
* The encoding format of the response body, such as `base64`.
|
|
186
|
-
*/
|
|
187
|
-
isBase64Encoded?: boolean;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* AWS Lambda HTTP Adapter for Stone.js.
|
|
192
|
-
*
|
|
193
|
-
* The `AwsLambdaHttpAdapter` extends the functionality of the Stone.js `Adapter`
|
|
194
|
-
* to provide seamless integration with AWS Lambda for HTTP-based events. This adapter
|
|
195
|
-
* transforms incoming HTTP events from AWS Lambda into `IncomingHttpEvent` instances
|
|
196
|
-
* and produces a `RawHttpResponse` as output.
|
|
197
|
-
*
|
|
198
|
-
* This adapter simplifies the process of handling HTTP events within AWS Lambda
|
|
199
|
-
* while adhering to the Stone.js framework's event-driven architecture.
|
|
200
|
-
*
|
|
201
|
-
* @template AwsLambdaHttpEvent - The type of the raw HTTP event from AWS Lambda.
|
|
202
|
-
* @template RawHttpResponse - The type of the raw HTTP response to send back.
|
|
203
|
-
* @template AwsLambdaContext - The AWS Lambda execution context type.
|
|
204
|
-
* @template IncomingHttpEvent - The type of the processed incoming HTTP event.
|
|
205
|
-
* @template IncomingHttpEventOptions - Options used to create an incoming HTTP event.
|
|
206
|
-
* @template OutgoingHttpResponse - The type of the outgoing HTTP response after processing.
|
|
207
|
-
* @template AwsLambdaHttpAdapterContext - Context type specific to the HTTP adapter.
|
|
208
|
-
*
|
|
209
|
-
* @extends Adapter
|
|
210
|
-
*
|
|
211
|
-
* @example
|
|
212
|
-
* ```typescript
|
|
213
|
-
* import { AwsLambdaHttpAdapter } from '@stone-js/aws-lambda-http-adapter';
|
|
214
|
-
*
|
|
215
|
-
* const adapter = AwsLambdaHttpAdapter.create({...});
|
|
216
|
-
*
|
|
217
|
-
* const handler = await adapter.run();
|
|
218
|
-
*
|
|
219
|
-
* export { handler };
|
|
220
|
-
* ```
|
|
221
|
-
*
|
|
222
|
-
* @see {@link https://stone-js.com/docs Stone.js Documentation}
|
|
223
|
-
* @see {@link https://docs.aws.amazon.com/lambda/latest/dg/ AWS Lambda Documentation}
|
|
224
|
-
*/
|
|
225
|
-
declare class AwsLambdaHttpAdapter extends Adapter<AwsLambdaHttpEvent, RawHttpResponse, AwsLambdaContext, IncomingHttpEvent, IncomingHttpEventOptions, OutgoingHttpResponse, AwsLambdaHttpAdapterContext> {
|
|
226
|
-
/**
|
|
227
|
-
* Creates an instance of the `AwsLambdaHttpAdapter`.
|
|
228
|
-
*
|
|
229
|
-
* @param blueprint - The application blueprint.
|
|
230
|
-
* @returns A new instance of `AwsLambdaHttpAdapter`.
|
|
231
|
-
*
|
|
232
|
-
* @example
|
|
233
|
-
* ```typescript
|
|
234
|
-
* const adapter = AwsLambdaHttpAdapter.create(blueprint);
|
|
235
|
-
* await adapter.run();
|
|
236
|
-
* ```
|
|
237
|
-
*/
|
|
238
|
-
static create(blueprint: IBlueprint): AwsLambdaHttpAdapter;
|
|
239
|
-
/**
|
|
240
|
-
* Executes the adapter and provides an AWS Lambda-compatible HTTP handler function.
|
|
241
|
-
*
|
|
242
|
-
* This method initializes the adapter and returns a handler function that can
|
|
243
|
-
* process HTTP events in AWS Lambda. It transforms raw events into `IncomingHttpEvent`
|
|
244
|
-
* instances and produces `RawHttpResponse` objects as output.
|
|
245
|
-
*
|
|
246
|
-
* @template ExecutionResultType - The type representing the AWS Lambda event handler function.
|
|
247
|
-
* @returns A promise resolving to the AWS Lambda HTTP handler function.
|
|
248
|
-
* @throws {AwsLambdaHttpAdapterError} If used outside the AWS Lambda environment.
|
|
249
|
-
*/
|
|
250
|
-
run<ExecutionResultType = AwsLambdaEventHandlerFunction<RawHttpResponse>>(): Promise<ExecutionResultType>;
|
|
251
|
-
/**
|
|
252
|
-
* Initializes the adapter and validates its execution context.
|
|
253
|
-
*
|
|
254
|
-
* Ensures that the adapter is running in an AWS Lambda environment. Throws an error
|
|
255
|
-
* if it detects that the adapter is being used in an unsupported environment (e.g., a browser).
|
|
256
|
-
*
|
|
257
|
-
* @throws {AwsLambdaHttpAdapterError} If executed outside an AWS Lambda environment.
|
|
258
|
-
*/
|
|
259
|
-
protected onStart(): Promise<void>;
|
|
260
|
-
/**
|
|
261
|
-
* Processes an incoming AWS Lambda HTTP event.
|
|
262
|
-
*
|
|
263
|
-
* Converts a raw AWS Lambda HTTP event into an `IncomingHttpEvent`, processes it through
|
|
264
|
-
* the Stone.js pipeline, and generates a `RawHttpResponse` to send back.
|
|
265
|
-
*
|
|
266
|
-
* @param rawEvent - The raw HTTP event received from AWS Lambda.
|
|
267
|
-
* @param executionContext - The AWS Lambda execution context associated with the event.
|
|
268
|
-
* @returns A promise resolving to the processed `RawHttpResponse`.
|
|
269
|
-
*/
|
|
270
|
-
protected eventListener(rawEvent: AwsLambdaHttpEvent, executionContext: AwsLambdaContext): Promise<RawHttpResponse>;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* AwsLambdaHttpErrorHandler options.
|
|
275
|
-
*/
|
|
276
|
-
interface AwsLambdaHttpErrorHandlerOptions {
|
|
277
|
-
blueprint: IBlueprint;
|
|
278
|
-
}
|
|
279
|
-
/**
|
|
280
|
-
* Class representing an AwsLambdaHttpErrorHandler.
|
|
281
|
-
*/
|
|
282
|
-
declare class AwsLambdaHttpErrorHandler implements IAdapterErrorHandler<AwsLambdaHttpEvent, RawHttpResponse, AwsLambdaContext> {
|
|
283
|
-
private readonly logger;
|
|
284
|
-
/**
|
|
285
|
-
* Create an NodeHttpErrorHandler.
|
|
286
|
-
*
|
|
287
|
-
* @param options - NodeHttpErrorHandler options.
|
|
288
|
-
*/
|
|
289
|
-
constructor({ blueprint }: AwsLambdaHttpErrorHandlerOptions);
|
|
290
|
-
/**
|
|
291
|
-
* Handle an error.
|
|
292
|
-
*
|
|
293
|
-
* @param error - The error to handle.
|
|
294
|
-
* @param context - The context of the adapter.
|
|
295
|
-
* @returns The raw response builder.
|
|
296
|
-
*/
|
|
297
|
-
handle(error: Error, context: AdapterErrorContext<AwsLambdaHttpEvent, RawHttpResponse, AwsLambdaContext>): AdapterEventBuilderType<RawHttpResponse>;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* A constant representing the AWS Lambda HTTP platform identifier.
|
|
302
|
-
*
|
|
303
|
-
* This constant is used as an alias for the AWS Lambda HTTP Adapter within the Stone.js framework.
|
|
304
|
-
* It helps in identifying and configuring platform-specific adapters or components for handling
|
|
305
|
-
* HTTP requests and responses.
|
|
306
|
-
*/
|
|
307
|
-
declare const AWS_LAMBDA_HTTP_PLATFORM = "aws_lambda_http";
|
|
308
|
-
|
|
309
|
-
/**
|
|
310
|
-
* Adapter resolver for AWS Lambda HTTP adapter.
|
|
311
|
-
*
|
|
312
|
-
* Creates and configures an `AWSLambdaHttpAdapter` for handling HTTP events in AWS Lambda.
|
|
313
|
-
*
|
|
314
|
-
* @param blueprint - The `IBlueprint` providing configuration and dependencies.
|
|
315
|
-
* @returns An `AWSLambdaHttpAdapter` instance.
|
|
316
|
-
*/
|
|
317
|
-
declare const awsLambdaHttpAdapterResolver: AdapterResolver;
|
|
318
|
-
|
|
319
|
-
/**
|
|
320
|
-
* Configuration interface for the AWS Lambda Http Adapter.
|
|
321
|
-
*
|
|
322
|
-
* Extends the `AdapterConfig` interface from the Stone.js framework and provides
|
|
323
|
-
* customizable options specific to the AWS Lambda platform. This includes
|
|
324
|
-
* alias, resolver, middleware, hooks, and various adapter state flags.
|
|
325
|
-
*/
|
|
326
|
-
interface AwsLambdaHttpAdapterAdapterConfig extends AdapterConfig<AwsLambdaHttpEvent, RawHttpResponse, AwsLambdaContext, IncomingHttpEvent, IncomingHttpEventOptions, OutgoingHttpResponse> {
|
|
327
|
-
}
|
|
328
|
-
/**
|
|
329
|
-
* Represents the AwsLambdaHttpAdapterConfig configuration options for the application.
|
|
330
|
-
*/
|
|
331
|
-
interface AwsLambdaHttpAdapterConfig extends Partial<AppConfig<IncomingHttpEvent, OutgoingHttpResponse>> {
|
|
332
|
-
http: Partial<HttpConfig>;
|
|
333
|
-
}
|
|
334
|
-
/**
|
|
335
|
-
* Blueprint interface for the AWS Lambda Http Adapter.
|
|
336
|
-
*
|
|
337
|
-
* This interface extends `StoneBlueprint` and defines the structure of the
|
|
338
|
-
* AWS Lambda Http adapter blueprint used in the Stone.js framework. It includes
|
|
339
|
-
* a `stone` object with an array of `AwsLambdaHttpAdapterConfig` items.
|
|
340
|
-
*/
|
|
341
|
-
interface AwsLambdaHttpAdapterBlueprint extends StoneBlueprint<IncomingHttpEvent, OutgoingHttpResponse> {
|
|
342
|
-
/**
|
|
343
|
-
* Application-level settings, including environment, middleware, logging, and service registration.
|
|
344
|
-
*/
|
|
345
|
-
stone: AwsLambdaHttpAdapterConfig;
|
|
346
|
-
}
|
|
347
|
-
/**
|
|
348
|
-
* Default blueprint configuration for the AWS Lambda Http Adapter.
|
|
349
|
-
*
|
|
350
|
-
* This blueprint defines the initial configuration for the AWS Lambda Http adapter
|
|
351
|
-
* within the Stone.js framework. It includes:
|
|
352
|
-
* - An alias for the AWS Lambda platform (`AWS_LAMBDA_HTTP_PLATFORM`).
|
|
353
|
-
* - A default resolver function (currently a placeholder).
|
|
354
|
-
* - Middleware, hooks, and state flags (`current`, `default`, `preferred`).
|
|
355
|
-
*/
|
|
356
|
-
declare const awsLambdaHttpAdapterBlueprint: AwsLambdaHttpAdapterBlueprint;
|
|
357
|
-
|
|
358
|
-
/**
|
|
359
|
-
* Configuration options for the `AwsLambdaHttp` decorator.
|
|
360
|
-
* These options extend the default AWS Lambda HTTP adapter configuration.
|
|
361
|
-
*/
|
|
362
|
-
interface AwsLambdaHttpOptions extends Partial<AwsLambdaHttpAdapterAdapterConfig> {
|
|
363
|
-
}
|
|
364
|
-
/**
|
|
365
|
-
* A Stone.js decorator that integrates the AWS Lambda HTTP Adapter with a class.
|
|
366
|
-
*
|
|
367
|
-
* This decorator modifies the class to seamlessly enable AWS Lambda HTTP as the
|
|
368
|
-
* execution environment for a Stone.js application. By applying this decorator,
|
|
369
|
-
* the class is automatically configured with the necessary blueprint for AWS Lambda HTTP.
|
|
370
|
-
*
|
|
371
|
-
* @template T - The type of the class being decorated. Defaults to `ClassType`.
|
|
372
|
-
* @param options - Optional configuration to customize the AWS Lambda HTTP Adapter.
|
|
373
|
-
*
|
|
374
|
-
* @returns A class decorator that applies the AWS Lambda HTTP adapter configuration.
|
|
375
|
-
*
|
|
376
|
-
* @example
|
|
377
|
-
* ```typescript
|
|
378
|
-
* import { AwsLambdaHttp } from '@stone-js/aws-lambda-http-adapter';
|
|
379
|
-
*
|
|
380
|
-
* @AwsLambdaHttp({
|
|
381
|
-
* alias: 'MyAwsLambdaHttpAdapter',
|
|
382
|
-
* current: true,
|
|
383
|
-
* })
|
|
384
|
-
* class App {
|
|
385
|
-
* // Your application logic here
|
|
386
|
-
* }
|
|
387
|
-
* ```
|
|
388
|
-
*/
|
|
389
|
-
declare const AwsLambdaHttp: <T extends ClassType = ClassType>(options?: AwsLambdaHttpOptions) => ClassDecorator;
|
|
390
|
-
|
|
391
|
-
/**
|
|
392
|
-
* Custom error for AWS Lambda adapter operations.
|
|
393
|
-
*/
|
|
394
|
-
declare class AwsLambdaHttpAdapterError extends IntegrationError {
|
|
395
|
-
constructor(message: string, options?: ErrorOptions);
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
/**
|
|
399
|
-
* Middleware to dynamically set response resolver for adapter.
|
|
400
|
-
*
|
|
401
|
-
* @param context - The configuration context containing modules and blueprint.
|
|
402
|
-
* @param next - The next pipeline function to continue processing.
|
|
403
|
-
* @returns The updated blueprint or a promise resolving to it.
|
|
404
|
-
*
|
|
405
|
-
* @example
|
|
406
|
-
* ```typescript
|
|
407
|
-
* SetAwsLambdaHttpResponseResolverMiddleware(context, next)
|
|
408
|
-
* ```
|
|
409
|
-
*/
|
|
410
|
-
declare const SetAwsLambdaHttpResponseResolverMiddleware: (context: BlueprintContext<IBlueprint, ClassType>, next: NextMiddleware<BlueprintContext<IBlueprint, ClassType>, IBlueprint>) => Promise<IBlueprint>;
|
|
411
|
-
/**
|
|
412
|
-
* Configuration for adapter processing middleware.
|
|
413
|
-
*
|
|
414
|
-
* This array defines a list of middleware pipes, each with a `pipe` function and a `priority`.
|
|
415
|
-
* These pipes are executed in the order of their priority values, with lower values running first.
|
|
416
|
-
*/
|
|
417
|
-
declare const metaAdapterBlueprintMiddleware: Array<MetaMiddleware<BlueprintContext<IBlueprint, ClassType>, IBlueprint>>;
|
|
418
|
-
|
|
419
|
-
/**
|
|
420
|
-
* Class representing a BodyEventMiddleware.
|
|
421
|
-
*
|
|
422
|
-
* This middleware handles platform-specific messages and transforms them into Stone.js IncomingEvent objects.
|
|
423
|
-
*
|
|
424
|
-
* @author Mr. Stone
|
|
425
|
-
*/
|
|
426
|
-
declare class BodyEventMiddleware {
|
|
427
|
-
/**
|
|
428
|
-
* The blueprint for resolving configuration and dependencies.
|
|
429
|
-
*/
|
|
430
|
-
private readonly blueprint;
|
|
431
|
-
/**
|
|
432
|
-
* Create a BodyEventMiddleware.
|
|
433
|
-
*
|
|
434
|
-
* @param {blueprint} options - Options for creating the BodyEventMiddleware.
|
|
435
|
-
*/
|
|
436
|
-
constructor({ blueprint }: {
|
|
437
|
-
blueprint: IBlueprint;
|
|
438
|
-
});
|
|
439
|
-
/**
|
|
440
|
-
* Handles the incoming event, processes it, and invokes the next middleware in the pipeline.
|
|
441
|
-
*
|
|
442
|
-
* @param context - The adapter context containing the raw event, execution context, and other data.
|
|
443
|
-
* @param next - The next middleware to be invoked in the pipeline.
|
|
444
|
-
* @returns A promise that resolves to the destination type after processing.
|
|
445
|
-
*
|
|
446
|
-
* @throws {AwsLambdaHttpAdapterError} If required components such as the rawEvent or IncomingEventBuilder are not provided.
|
|
447
|
-
*/
|
|
448
|
-
handle(context: AwsLambdaHttpAdapterContext, next: NextMiddleware<AwsLambdaHttpAdapterContext, AwsLambdaHttpAdapterResponseBuilder>): Promise<AwsLambdaHttpAdapterResponseBuilder>;
|
|
449
|
-
/**
|
|
450
|
-
* Convert the raw event into a Node.js IncomingMessage.
|
|
451
|
-
*
|
|
452
|
-
* @param rawEvent - The raw event from the platform.
|
|
453
|
-
* @returns The converted IncomingMessage.
|
|
454
|
-
*/
|
|
455
|
-
private toNodeMessage;
|
|
456
|
-
/**
|
|
457
|
-
* Extract and parse the body from the message.
|
|
458
|
-
*
|
|
459
|
-
* @param message - The incoming HTTP message.
|
|
460
|
-
* @returns A Promise resolving to the parsed body.
|
|
461
|
-
* @throws {AwsLambdaHttpAdapterError} If the body parsing fails or is invalid.
|
|
462
|
-
*/
|
|
463
|
-
private getBody;
|
|
464
|
-
/**
|
|
465
|
-
* Get the normalized raw body from the event.
|
|
466
|
-
*
|
|
467
|
-
* @param rawEvent - The raw event containing the body.
|
|
468
|
-
* @param encoding - The encoding to use for the body.
|
|
469
|
-
* @returns The normalized body as a string.
|
|
470
|
-
*/
|
|
471
|
-
private getNormalizedRawBody;
|
|
472
|
-
/**
|
|
473
|
-
* Parse the body content based on the specified type and encoding.
|
|
474
|
-
*
|
|
475
|
-
* @param type - The content type of the body.
|
|
476
|
-
* @param body - The raw body content as a string.
|
|
477
|
-
* @param encoding - The encoding of the body content.
|
|
478
|
-
* @returns The parsed body content as an object, string, or Buffer.
|
|
479
|
-
* @throws {AwsLambdaHttpAdapterError} If parsing fails.
|
|
480
|
-
*/
|
|
481
|
-
private parseBodyContent;
|
|
482
|
-
}
|
|
483
|
-
/**
|
|
484
|
-
* Meta Middleware for processing the request body.
|
|
485
|
-
*/
|
|
486
|
-
declare const MetaBodyEventMiddleware: {
|
|
487
|
-
module: typeof BodyEventMiddleware;
|
|
488
|
-
isClass: boolean;
|
|
489
|
-
};
|
|
490
|
-
|
|
491
|
-
/**
|
|
492
|
-
* Class representing a FilesEventMiddleware.
|
|
493
|
-
*
|
|
494
|
-
* @author Mr. Stone <evensstone@gmail.com>
|
|
495
|
-
*/
|
|
496
|
-
declare class FilesEventMiddleware {
|
|
497
|
-
/**
|
|
498
|
-
* The blueprint for resolving configuration and dependencies.
|
|
499
|
-
*/
|
|
500
|
-
private readonly blueprint;
|
|
501
|
-
/**
|
|
502
|
-
* Create a FilesEventMiddleware.
|
|
503
|
-
*
|
|
504
|
-
* @param {blueprint} options - Options for creating the FilesEventMiddleware.
|
|
505
|
-
*/
|
|
506
|
-
constructor({ blueprint }: {
|
|
507
|
-
blueprint: IBlueprint;
|
|
508
|
-
});
|
|
509
|
-
/**
|
|
510
|
-
* Handles the incoming event, processes it, and invokes the next middleware in the pipeline.
|
|
511
|
-
*
|
|
512
|
-
* @param context - The adapter context containing the raw event, execution context, and other data.
|
|
513
|
-
* @param next - The next middleware to be invoked in the pipeline.
|
|
514
|
-
* @returns A promise that resolves to the destination type after processing.
|
|
515
|
-
*
|
|
516
|
-
* @throws {AwsLambdaHttpAdapterError} If required components such as the rawEvent or IncomingEventBuilder are not provided.
|
|
517
|
-
*/
|
|
518
|
-
handle(context: AwsLambdaHttpAdapterContext, next: NextMiddleware<AwsLambdaHttpAdapterContext, AwsLambdaHttpAdapterResponseBuilder>): Promise<AwsLambdaHttpAdapterResponseBuilder>;
|
|
519
|
-
/**
|
|
520
|
-
* Normalize the incoming event to an IncomingMessage.
|
|
521
|
-
*
|
|
522
|
-
* @param rawEvent - The raw event to be normalized.
|
|
523
|
-
* @returns The normalized event.
|
|
524
|
-
*/
|
|
525
|
-
private normalizeEvent;
|
|
526
|
-
}
|
|
527
|
-
/**
|
|
528
|
-
* Meta Middleware for processing files uploads.
|
|
529
|
-
*/
|
|
530
|
-
declare const MetaFilesEventMiddleware: {
|
|
531
|
-
module: typeof FilesEventMiddleware;
|
|
532
|
-
isClass: boolean;
|
|
533
|
-
};
|
|
534
|
-
|
|
535
|
-
/**
|
|
536
|
-
* Middleware for handling incoming events and transforming them into Stone.js events.
|
|
537
|
-
*
|
|
538
|
-
* This class processes incoming HTTP requests, extracting relevant data such as URL, IP addresses,
|
|
539
|
-
* headers, cookies, and more, and forwards them to the next middleware in the pipeline.
|
|
540
|
-
*/
|
|
541
|
-
declare class IncomingEventMiddleware {
|
|
542
|
-
/**
|
|
543
|
-
* The blueprint for resolving configuration and dependencies.
|
|
544
|
-
*/
|
|
545
|
-
private readonly blueprint;
|
|
546
|
-
/**
|
|
547
|
-
* Create an IncomingEventMiddleware instance.
|
|
548
|
-
*
|
|
549
|
-
* @param {blueprint} options - Options containing the blueprint for resolving configuration and dependencies.
|
|
550
|
-
*/
|
|
551
|
-
constructor({ blueprint }: {
|
|
552
|
-
blueprint: IBlueprint;
|
|
553
|
-
});
|
|
554
|
-
/**
|
|
555
|
-
* Handles the incoming event, processes it, and invokes the next middleware in the pipeline.
|
|
556
|
-
*
|
|
557
|
-
* @param context - The adapter context containing the raw event, execution context, and other data.
|
|
558
|
-
* @param next - The next middleware to be invoked in the pipeline.
|
|
559
|
-
* @returns A promise that resolves to the processed context.
|
|
560
|
-
* @throws {AwsLambdaHttpAdapterError} If required components are missing in the context.
|
|
561
|
-
*/
|
|
562
|
-
handle(context: AwsLambdaHttpAdapterContext, next: NextMiddleware<AwsLambdaHttpAdapterContext, AwsLambdaHttpAdapterResponseBuilder>): Promise<AwsLambdaHttpAdapterResponseBuilder>;
|
|
563
|
-
/**
|
|
564
|
-
* Create the IncomingEventSource from the context.
|
|
565
|
-
*
|
|
566
|
-
* @param context - The adapter context containing the raw event, execution context, and other data.
|
|
567
|
-
* @returns The Incoming Event Source.
|
|
568
|
-
*/
|
|
569
|
-
private getSource;
|
|
570
|
-
/**
|
|
571
|
-
* Extracts the HTTP method from the incoming rawEvent.
|
|
572
|
-
*
|
|
573
|
-
* @param rawEvent - The incoming rawEvent.
|
|
574
|
-
* @returns The HTTP method string.
|
|
575
|
-
*/
|
|
576
|
-
private getMethod;
|
|
577
|
-
/**
|
|
578
|
-
* Extracts proxy-related options from the blueprint.
|
|
579
|
-
*
|
|
580
|
-
* @returns Proxy options.
|
|
581
|
-
*/
|
|
582
|
-
private getProxyOptions;
|
|
583
|
-
/**
|
|
584
|
-
* Retrieves cookie-related options from the blueprint.
|
|
585
|
-
*
|
|
586
|
-
* @returns Cookie options.
|
|
587
|
-
*/
|
|
588
|
-
private getCookieOptions;
|
|
589
|
-
/**
|
|
590
|
-
* Retrieves the cookie secret from the blueprint.
|
|
591
|
-
*
|
|
592
|
-
* @returns The cookie secret string.
|
|
593
|
-
*/
|
|
594
|
-
private getCookieSecret;
|
|
595
|
-
/**
|
|
596
|
-
* Extracts and parses the URL from the incoming rawEvent.
|
|
597
|
-
*
|
|
598
|
-
* @param rawEvent - The incoming HTTP rawEvent.
|
|
599
|
-
* @param options - Proxy options.
|
|
600
|
-
* @returns The parsed URL object.
|
|
601
|
-
*/
|
|
602
|
-
private extractUrl;
|
|
603
|
-
/**
|
|
604
|
-
* Extracts a list of IP addresses from the incoming rawEvent.
|
|
605
|
-
*
|
|
606
|
-
* @param rawEvent - The incoming HTTP rawEvent.
|
|
607
|
-
* @param options - Proxy options.
|
|
608
|
-
* @returns An array of IP addresses.
|
|
609
|
-
*/
|
|
610
|
-
private extractIpAddresses;
|
|
611
|
-
/**
|
|
612
|
-
* Converts the incoming rawEvent to a Node.js IncomingMessage.
|
|
613
|
-
*
|
|
614
|
-
* @param rawEvent - The incoming rawEvent.
|
|
615
|
-
* @returns The converted IncomingMessage.
|
|
616
|
-
*/
|
|
617
|
-
private toNodeMessage;
|
|
618
|
-
/**
|
|
619
|
-
* Determines the protocol from the incoming rawEvent.
|
|
620
|
-
*
|
|
621
|
-
* @param rawEvent - The incoming rawEvent.
|
|
622
|
-
* @param options - Proxy options.
|
|
623
|
-
* @returns The protocol string.
|
|
624
|
-
*/
|
|
625
|
-
private getProtocol;
|
|
626
|
-
/**
|
|
627
|
-
* Retrieves the remote address from the incoming rawEvent.
|
|
628
|
-
* This method is used as a fallback when the remote address is not found in the rawEvent.
|
|
629
|
-
* @param rawEvent - The incoming rawEvent.
|
|
630
|
-
* @returns The remote address string.
|
|
631
|
-
*/
|
|
632
|
-
private getRemoteAddress;
|
|
633
|
-
}
|
|
634
|
-
/**
|
|
635
|
-
* Meta Middleware for processing incoming events.
|
|
636
|
-
*/
|
|
637
|
-
declare const MetaIncomingEventMiddleware: {
|
|
638
|
-
module: typeof IncomingEventMiddleware;
|
|
639
|
-
isClass: boolean;
|
|
640
|
-
};
|
|
641
|
-
|
|
642
|
-
/**
|
|
643
|
-
* Middleware for handling server responses and transforming them into the appropriate HTTP responses.
|
|
644
|
-
*
|
|
645
|
-
* This middleware processes outgoing responses and attaches the necessary headers, status codes,
|
|
646
|
-
* and body content to the HTTP response.
|
|
647
|
-
*/
|
|
648
|
-
declare class ServerResponseMiddleware {
|
|
649
|
-
/**
|
|
650
|
-
* Handles the outgoing response, processes it, and invokes the next middleware in the pipeline.
|
|
651
|
-
*
|
|
652
|
-
* @param context - The adapter context containing the raw event, execution context, and other data.
|
|
653
|
-
* @param next - The next middleware to be invoked in the pipeline.
|
|
654
|
-
* @returns A promise resolving to the rawResponseBuilder.
|
|
655
|
-
* @throws {AwsLambdaHttpAdapterError} If required components are missing in the context.
|
|
656
|
-
*/
|
|
657
|
-
handle(context: AwsLambdaHttpAdapterContext, next: NextMiddleware<AwsLambdaHttpAdapterContext, AwsLambdaHttpAdapterResponseBuilder>): Promise<AwsLambdaHttpAdapterResponseBuilder>;
|
|
658
|
-
}
|
|
659
|
-
/**
|
|
660
|
-
* Meta Middleware for processing server responses.
|
|
661
|
-
*/
|
|
662
|
-
declare const MetaServerResponseMiddleware: {
|
|
663
|
-
module: typeof ServerResponseMiddleware;
|
|
664
|
-
isClass: boolean;
|
|
665
|
-
};
|
|
666
|
-
|
|
667
|
-
export { AWS_LAMBDA_HTTP_PLATFORM, AwsLambdaHttp, AwsLambdaHttpAdapter, AwsLambdaHttpAdapterError, AwsLambdaHttpErrorHandler, BodyEventMiddleware, FilesEventMiddleware, IncomingEventMiddleware, MetaBodyEventMiddleware, MetaFilesEventMiddleware, MetaIncomingEventMiddleware, MetaServerResponseMiddleware, RawHttpResponseWrapper, ServerResponseMiddleware, SetAwsLambdaHttpResponseResolverMiddleware, awsLambdaHttpAdapterBlueprint, awsLambdaHttpAdapterResolver, metaAdapterBlueprintMiddleware };
|
|
668
|
-
export type { AwsLambdaContext, AwsLambdaEventHandlerFunction, AwsLambdaHttpAdapterAdapterConfig, AwsLambdaHttpAdapterBlueprint, AwsLambdaHttpAdapterConfig, AwsLambdaHttpAdapterContext, AwsLambdaHttpAdapterResponseBuilder, AwsLambdaHttpErrorHandlerOptions, AwsLambdaHttpEvent, AwsLambdaHttpOptions, RawHttpResponse, RawHttpResponseOptions };
|
|
1
|
+
export * from './AWSLambdaHttpAdapter';
|
|
2
|
+
export * from './AwsLambdaHttpErrorHandler';
|
|
3
|
+
export * from './RawHttpResponseWrapper';
|
|
4
|
+
export * from './constants';
|
|
5
|
+
export * from './declarations';
|
|
6
|
+
export * from './decorators/AwsLambdaHttp';
|
|
7
|
+
export * from './errors/AwsLambdaHttpAdapterError';
|
|
8
|
+
export * from './event-normalizer';
|
|
9
|
+
export * from './middleware/BlueprintMiddleware';
|
|
10
|
+
export * from './middleware/BodyEventMiddleware';
|
|
11
|
+
export * from './middleware/FilesEventMiddleware';
|
|
12
|
+
export * from './middleware/IncomingEventMiddleware';
|
|
13
|
+
export * from './middleware/ServerResponseMiddleware';
|
|
14
|
+
export * from './options/AwsLambdaHttpAdapterBlueprint';
|
|
15
|
+
export * from './resolvers';
|