New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@stone-js/aws-lambda-adapter

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stone-js/aws-lambda-adapter - npm Package Compare versions

Comparing version 0.0.2 to 0.0.22

348

dist/index.d.ts

@@ -0,3 +1,3 @@

import { IRawResponseWrapper, RawResponseOptions, IAdapterEventBuilder, AdapterContext, IncomingEvent, IncomingEventOptions, OutgoingResponse, Adapter, AdapterOptions, ILogger, IAdapterErrorHandler, AdapterErrorContext, AdapterResolver, AdapterConfig, StoneBlueprint, ClassType, IntegrationError, ErrorOptions, IBlueprint } from '@stone-js/core';
import { IncomingHttpEvent, IncomingHttpEventOptions, OutgoingHttpResponse } from '@stone-js/http-core';
import { AdapterContext, IncomingEvent, IncomingEventOptions, OutgoingResponse, RawResponseOptions, Adapter, AdapterOptions, IRawResponseWrapper, ErrorHandlerResolver, AdapterResolver, AdapterConfig, StoneBlueprint, ClassType, IntegrationError, ErrorOptions, IBlueprint } from '@stone-js/core';
import { IncomingMessage } from 'node:http';

@@ -7,2 +7,122 @@ import { NextPipe } from '@stone-js/pipeline';

/**
* Wrapper for generic raw responses.
*
* The `RawResponseWrapper` is responsible for encapsulating a raw response
* and returning it in a structure that aligns with the Stone.js framework's requirements.
* It implements the `IRawResponseWrapper` interface, ensuring compatibility with the framework.
*/
declare class RawResponseWrapper implements IRawResponseWrapper<RawResponse> {
private readonly options;
/**
* Factory method to create an instance of `RawResponseWrapper`.
*
* This method initializes the wrapper with a set of partial response options.
*
* @param options - Partial options to configure the raw response.
* @returns A new instance of `RawResponseWrapper`.
*
* @example
* ```typescript
* const responseWrapper = RawResponseWrapper.create({
* headers: { 'Content-Type': 'application/json' },
* body: { message: 'Success' },
* statusCode: 200,
* });
*
* const response = responseWrapper.respond();
* console.log(response); // { headers: { 'Content-Type': 'application/json' }, body: { message: 'Success' }, statusCode: 200 }
* ```
*/
static create(options: Partial<RawResponseOptions>): RawResponseWrapper;
/**
* Constructs an instance of `RawResponseWrapper`.
*
* This constructor is private and should not be called directly.
* Use the `create` method to initialize an instance.
*
* @param options - Partial options for configuring the raw response.
*/
private constructor();
/**
* Constructs and returns the raw response.
*
* The `respond` method generates and returns the raw response based on
* the provided options. The response is returned as-is, allowing for
* maximum flexibility in defining its structure.
*
* @returns A `RawResponse` object containing the response options.
*
* @example
* ```typescript
* const responseWrapper = RawResponseWrapper.create({ body: 'Hello, world!' });
* const response = responseWrapper.respond();
* console.log(response); // { body: 'Hello, world!' }
* ```
*/
respond(): RawResponse;
}
/**
* Wrapper for HTTP raw responses in AWS Lambda.
*
* The `RawHttpResponseWrapper` is responsible for constructing and returning
* a raw HTTP response that conforms to the expected structure for AWS Lambda.
* It implements the `IRawResponseWrapper` interface, ensuring compatibility
* with the Stone.js framework.
*/
declare class RawHttpResponseWrapper implements IRawResponseWrapper<RawHttpResponse> {
private readonly options;
/**
* Factory method to create an instance of `RawHttpResponseWrapper`.
*
* This method accepts partial response options, allowing the user to configure
* only the required fields. It initializes the wrapper with these options.
*
* @param options - Partial options to configure the HTTP response.
* @returns A new instance of `RawHttpResponseWrapper`.
*
* @example
* ```typescript
* const responseWrapper = RawHttpResponseWrapper.create({
* statusCode: 200,
* body: { message: 'Success' },
* headers: { 'Content-Type': 'application/json' }
* });
*
* const response = responseWrapper.respond();
* console.log(response); // { statusCode: 200, body: '{"message":"Success"}', headers: { 'Content-Type': 'application/json' } }
* ```
*/
static create(options: Partial<RawHttpResponseOptions>): RawHttpResponseWrapper;
/**
* Constructs an instance of `RawHttpResponseWrapper`.
*
* This constructor is private and should not be called directly.
* Use the `create` method to initialize an instance.
*
* @param options - Partial options for configuring the HTTP response.
*/
private constructor();
/**
* Constructs and returns the raw HTTP response.
*
* The `respond` method generates a `RawHttpResponse` object based on the
* provided options. If any required fields are missing, it assigns default values:
* - `statusCode`: Defaults to `500`.
* - `statusMessage`: Defaults to an empty string.
* - `body`: Converts non-string bodies to a JSON string.
*
* @returns A `RawHttpResponse` object.
*
* @example
* ```typescript
* const responseWrapper = RawHttpResponseWrapper.create({ body: 'Hello, world!', statusCode: 200 });
* const response = responseWrapper.respond();
* console.log(response); // { statusCode: 500, statusMessage: '', body: 'Hello, world!', headers: undefined }
* ```
*/
respond(): RawHttpResponse;
}
/**
* Represents a generic raw response as a key-value pair.

@@ -33,2 +153,10 @@ */

/**
* Represents the response builder for the AWS Lambda Adapter.
*/
type AwsLambdaAdapterResponseBuilder = IAdapterEventBuilder<RawResponseOptions, RawResponseWrapper>;
/**
* Represents the response builder for the AWS Lambda http Adapter.
*/
type AwsLambdaHttpAdapterResponseBuilder = IAdapterEventBuilder<RawHttpResponseOptions, RawHttpResponseWrapper>;
/**
* Represents the structure of an AWS Lambda HTTP event.

@@ -182,3 +310,3 @@ *

*/
static create(options: AdapterOptions<RawResponse, IncomingEvent, OutgoingResponse>): AWSLambdaAdapter;
static create(options: AdapterOptions<IncomingEvent, OutgoingResponse>): AWSLambdaAdapter;
/**

@@ -263,3 +391,3 @@ * Executes the adapter and provides an AWS Lambda-compatible handler function.

*/
static create(options: AdapterOptions<RawHttpResponse, IncomingHttpEvent, OutgoingHttpResponse>): AWSLambdaHttpAdapter;
static create(options: AdapterOptions<IncomingHttpEvent, OutgoingHttpResponse>): AWSLambdaHttpAdapter;
/**

@@ -300,119 +428,53 @@ * Executes the adapter and provides an AWS Lambda-compatible HTTP handler function.

/**
* Wrapper for generic raw responses.
*
* The `RawResponseWrapper` is responsible for encapsulating a raw response
* and returning it in a structure that aligns with the Stone.js framework's requirements.
* It implements the `IRawResponseWrapper` interface, ensuring compatibility with the framework.
* AwsLambdaErrorHandler options.
*/
declare class RawResponseWrapper implements IRawResponseWrapper<RawResponse> {
private readonly options;
interface AwsLambdaErrorHandlerOptions {
logger: ILogger;
}
/**
* Class representing an AwsLambdaErrorHandler.
*/
declare class AwsLambdaErrorHandler implements IAdapterErrorHandler<AwsLambdaEvent, RawResponse, AwsLambdaContext> {
private readonly logger;
/**
* Factory method to create an instance of `RawResponseWrapper`.
* Create an AwsLambdaErrorHandler.
*
* This method initializes the wrapper with a set of partial response options.
*
* @param options - Partial options to configure the raw response.
* @returns A new instance of `RawResponseWrapper`.
*
* @example
* ```typescript
* const responseWrapper = RawResponseWrapper.create({
* headers: { 'Content-Type': 'application/json' },
* body: { message: 'Success' },
* statusCode: 200,
* });
*
* const response = responseWrapper.respond();
* console.log(response); // { headers: { 'Content-Type': 'application/json' }, body: { message: 'Success' }, statusCode: 200 }
* ```
* @param options - AwsLambdaErrorHandler options.
*/
static create(options: Partial<RawResponseOptions>): RawResponseWrapper;
constructor({ logger }: AwsLambdaErrorHandlerOptions);
/**
* Constructs an instance of `RawResponseWrapper`.
* Handle an error.
*
* This constructor is private and should not be called directly.
* Use the `create` method to initialize an instance.
*
* @param options - Partial options for configuring the raw response.
* @param error - The error to handle.
* @param context - The context of the adapter.
* @returns The raw response.
*/
private constructor();
/**
* Constructs and returns the raw response.
*
* The `respond` method generates and returns the raw response based on
* the provided options. The response is returned as-is, allowing for
* maximum flexibility in defining its structure.
*
* @returns A `RawResponse` object containing the response options.
*
* @example
* ```typescript
* const responseWrapper = RawResponseWrapper.create({ body: 'Hello, world!' });
* const response = responseWrapper.respond();
* console.log(response); // { body: 'Hello, world!' }
* ```
*/
respond(): RawResponse;
handle(error: Error, context: AdapterErrorContext<AwsLambdaEvent, RawResponse, AwsLambdaContext>): Promise<RawResponse>;
}
/**
* Wrapper for HTTP raw responses in AWS Lambda.
*
* The `RawHttpResponseWrapper` is responsible for constructing and returning
* a raw HTTP response that conforms to the expected structure for AWS Lambda.
* It implements the `IRawResponseWrapper` interface, ensuring compatibility
* with the Stone.js framework.
* AwsLambdaHttpErrorHandler options.
*/
declare class RawHttpResponseWrapper implements IRawResponseWrapper<RawHttpResponse> {
private readonly options;
interface AwsLambdaHttpErrorHandlerOptions {
logger: ILogger;
}
/**
* Class representing an AwsLambdaHttpErrorHandler.
*/
declare class AwsLambdaHttpErrorHandler implements IAdapterErrorHandler<AwsLambdaHttpEvent, RawHttpResponse, AwsLambdaContext> {
private readonly logger;
/**
* Factory method to create an instance of `RawHttpResponseWrapper`.
* Create an AwsLambdaHttpErrorHandler.
*
* This method accepts partial response options, allowing the user to configure
* only the required fields. It initializes the wrapper with these options.
*
* @param options - Partial options to configure the HTTP response.
* @returns A new instance of `RawHttpResponseWrapper`.
*
* @example
* ```typescript
* const responseWrapper = RawHttpResponseWrapper.create({
* statusCode: 200,
* body: { message: 'Success' },
* headers: { 'Content-Type': 'application/json' }
* });
*
* const response = responseWrapper.respond();
* console.log(response); // { statusCode: 200, body: '{"message":"Success"}', headers: { 'Content-Type': 'application/json' } }
* ```
* @param options - AwsLambdaHttpErrorHandler options.
*/
static create(options: Partial<RawHttpResponseOptions>): RawHttpResponseWrapper;
constructor({ logger }: AwsLambdaHttpErrorHandlerOptions);
/**
* Constructs an instance of `RawHttpResponseWrapper`.
* Handle an error.
*
* This constructor is private and should not be called directly.
* Use the `create` method to initialize an instance.
*
* @param options - Partial options for configuring the HTTP response.
* @param error - The error to handle.
* @param context - The context of the adapter.
* @returns The raw response.
*/
private constructor();
/**
* Constructs and returns the raw HTTP response.
*
* The `respond` method generates a `RawHttpResponse` object based on the
* provided options. If any required fields are missing, it assigns default values:
* - `statusCode`: Defaults to `500`.
* - `statusMessage`: Defaults to an empty string.
* - `body`: Converts non-string bodies to a JSON string.
*
* @returns A `RawHttpResponse` object.
*
* @example
* ```typescript
* const responseWrapper = RawHttpResponseWrapper.create({ body: 'Hello, world!', statusCode: 200 });
* const response = responseWrapper.respond();
* console.log(response); // { statusCode: 500, statusMessage: '', body: 'Hello, world!', headers: undefined }
* ```
*/
respond(): RawHttpResponse;
handle(error: Error, context: AdapterErrorContext<AwsLambdaHttpEvent, RawHttpResponse, AwsLambdaContext>): Promise<RawHttpResponse>;
}

@@ -438,20 +500,2 @@

/**
* Error handler resolver for generic AWS Lambda adapter.
*
* Creates and configures an `ErrorHandler` for managing errors in the generic AWS Lambda adapter.
*
* @param blueprint - The `IBlueprint` providing configuration and dependencies.
* @returns An `ErrorHandler` instance for handling AWS Lambda errors.
*/
declare const awsLambdaErrorHandlerResolver: ErrorHandlerResolver<RawResponse>;
/**
* Error handler resolver for AWS Lambda HTTP adapter.
*
* Creates and configures an `ErrorHandler` for managing errors in the AWS Lambda HTTP adapter.
*
* @param blueprint - The `IBlueprint` providing configuration and dependencies.
* @returns An `ErrorHandler` instance for handling AWS Lambda HTTP errors.
*/
declare const awsLambdaHttpErrorHandlerResolver: ErrorHandlerResolver<RawHttpResponse>;
/**
* Adapter resolver for generic AWS Lambda adapter.

@@ -482,3 +526,3 @@ *

*/
interface AwsLambaAdapterConfig extends AdapterConfig {
interface AwsLambdaAdapterConfig extends AdapterConfig {
}

@@ -490,5 +534,5 @@ /**

* AWS Lambda adapter blueprint used in the Stone.js framework. It includes
* a `stone` object with an array of `AwsLambaAdapterConfig` items.
* a `stone` object with an array of `AwsLambdaAdapterConfig` items.
*/
interface AwsLambaAdapterBlueprint extends StoneBlueprint {
interface AwsLambdaAdapterBlueprint extends StoneBlueprint {
}

@@ -504,9 +548,9 @@ /**

*/
declare const awsLambaAdapterBlueprint: AwsLambaAdapterBlueprint;
declare const awsLambdaAdapterBlueprint: AwsLambdaAdapterBlueprint;
/**
* Configuration options for the `AwsLambdaAdapter` decorator.
* Configuration options for the `AwsLambda` decorator.
* These options extend the default AWS Lambda adapter configuration.
*/
interface AwsLambdaAdapterOptions extends Partial<AwsLambaAdapterConfig> {
interface AwsLambdaOptions extends Partial<AwsLambdaAdapterConfig> {
}

@@ -527,6 +571,6 @@ /**

* ```typescript
* import { AwsLambdaAdapter } from '@stone-js/aws-lambda-adapter';
* import { AwsLambda } from '@stone-js/aws-lambda-adapter';
*
* @AwsLambdaAdapter({
* alias: 'MyAWSLambdaAdapter',
* @AwsLambda({
* alias: 'MyAWSLambda',
* })

@@ -538,3 +582,3 @@ * class App {

*/
declare const AwsLambdaAdapter: <T extends ClassType = ClassType>(options?: AwsLambdaAdapterOptions) => ((target: T, context: ClassDecoratorContext<T>) => void);
declare const AwsLambda: <T extends ClassType = ClassType>(options?: AwsLambdaOptions) => ((target: T, context: ClassDecoratorContext<T>) => void);

@@ -548,3 +592,3 @@ /**

*/
interface AwsLambaHttpAdapterConfig extends AdapterConfig {
interface AwsLambdaHttpAdapterConfig extends AdapterConfig {
}

@@ -556,5 +600,5 @@ /**

* AWS Lambda Http adapter blueprint used in the Stone.js framework. It includes
* a `stone` object with an array of `AwsLambaHttpAdapterConfig` items.
* a `stone` object with an array of `AwsLambdaHttpAdapterConfig` items.
*/
interface AwsLambaHttpAdapterBlueprint extends StoneBlueprint<IncomingHttpEvent, OutgoingHttpResponse> {
interface AwsLambdaHttpAdapterBlueprint extends StoneBlueprint<IncomingHttpEvent, OutgoingHttpResponse> {
}

@@ -570,9 +614,9 @@ /**

*/
declare const awsLambaHttpAdapterBlueprint: AwsLambaHttpAdapterBlueprint;
declare const awsLambdaHttpAdapterBlueprint: AwsLambdaHttpAdapterBlueprint;
/**
* Configuration options for the `AwsLambdaHttpAdapter` decorator.
* Configuration options for the `AwsLambdaHttp` decorator.
* These options extend the default AWS Lambda HTTP adapter configuration.
*/
interface AwsLambdaHttpAdapterOptions extends Partial<AwsLambaHttpAdapterConfig> {
interface AwsLambdaHttpOptions extends Partial<AwsLambdaHttpAdapterConfig> {
}

@@ -593,5 +637,5 @@ /**

* ```typescript
* import { AwsLambdaHttpAdapter } from '@stone-js/aws-lambda-adapter';
* import { AwsLambdaHttp } from '@stone-js/aws-lambda-adapter';
*
* @AwsLambdaHttpAdapter({
* @AwsLambdaHttp({
* alias: 'MyAwsLambdaHttpAdapter',

@@ -605,3 +649,3 @@ * current: true,

*/
declare const AwsLambdaHttpAdapter: <T extends ClassType = ClassType>(options?: AwsLambdaHttpAdapterOptions) => ((target: T, context: ClassDecoratorContext<T>) => void);
declare const AwsLambdaHttp: <T extends ClassType = ClassType>(options?: AwsLambdaHttpOptions) => ((target: T, context: ClassDecoratorContext<T>) => void);

@@ -644,3 +688,3 @@ /**

*/
handle(context: AwsLambdaHttpAdapterContext, next: NextPipe<AwsLambdaHttpAdapterContext, RawHttpResponseWrapper>): Promise<RawHttpResponseWrapper>;
handle(context: AwsLambdaHttpAdapterContext, next: NextPipe<AwsLambdaHttpAdapterContext, AwsLambdaHttpAdapterResponseBuilder>): Promise<AwsLambdaHttpAdapterResponseBuilder>;
toNodeMessage(rawEvent: AwsLambdaHttpEvent): IncomingMessage;

@@ -684,3 +728,3 @@ /**

*/
handle(context: AwsLambdaHttpAdapterContext, next: NextPipe<AwsLambdaHttpAdapterContext, RawHttpResponseWrapper>): Promise<RawHttpResponseWrapper>;
handle(context: AwsLambdaHttpAdapterContext, next: NextPipe<AwsLambdaHttpAdapterContext, AwsLambdaHttpAdapterResponseBuilder>): Promise<AwsLambdaHttpAdapterResponseBuilder>;
/**

@@ -722,3 +766,3 @@ * Normalize the incoming event to an IncomingMessage.

*/
handle(context: AwsLambdaHttpAdapterContext, next: NextPipe<AwsLambdaHttpAdapterContext, RawHttpResponseWrapper>): Promise<RawHttpResponseWrapper>;
handle(context: AwsLambdaHttpAdapterContext, next: NextPipe<AwsLambdaHttpAdapterContext, AwsLambdaHttpAdapterResponseBuilder>): Promise<AwsLambdaHttpAdapterResponseBuilder>;
/**

@@ -797,14 +841,2 @@ * Extracts the HTTP method from the incoming rawEvent.

/**
* The blueprint for resolving configuration and dependencies.
*/
private readonly blueprint;
/**
* Create a ServerResponseMiddleware.
*
* @param {blueprint} options - Options for creating the ServerResponseMiddleware.
*/
constructor({ blueprint }: {
blueprint: IBlueprint;
});
/**
* Handles the outgoing response, processes it, and invokes the next middleware in the pipeline.

@@ -814,8 +846,8 @@ *

* @param next - The next middleware to be invoked in the pipeline.
* @returns A promise resolving to the processed context.
* @returns A promise resolving to the rawResponseBuilder.
* @throws {AwsLambdaAdapterError} If required components are missing in the context.
*/
handle(context: AwsLambdaHttpAdapterContext, next: NextPipe<AwsLambdaHttpAdapterContext, RawHttpResponseWrapper>): Promise<RawHttpResponseWrapper>;
handle(context: AwsLambdaHttpAdapterContext, next: NextPipe<AwsLambdaHttpAdapterContext, AwsLambdaHttpAdapterResponseBuilder>): Promise<AwsLambdaHttpAdapterResponseBuilder>;
}
export { AWSLambdaAdapter, AWSLambdaHttpAdapter, AWS_LAMBDA_HTTP_PLATFORM, AWS_LAMBDA_PLATFORM, type AwsLambaAdapterBlueprint, type AwsLambaAdapterConfig, type AwsLambaHttpAdapterBlueprint, type AwsLambaHttpAdapterConfig, AwsLambdaAdapter, type AwsLambdaAdapterContext, AwsLambdaAdapterError, type AwsLambdaAdapterOptions, type AwsLambdaContext, type AwsLambdaEvent, type AwsLambdaEventHandlerFunction, AwsLambdaHttpAdapter, type AwsLambdaHttpAdapterContext, type AwsLambdaHttpAdapterOptions, type AwsLambdaHttpEvent, BodyEventMiddleware, FilesEventMiddleware, IncomingEventMiddleware, type RawHttpResponse, type RawHttpResponseOptions, RawHttpResponseWrapper, type RawResponse, RawResponseWrapper, ServerResponseMiddleware, awsLambaAdapterBlueprint, awsLambaHttpAdapterBlueprint, awsLambdaAdapterResolver, awsLambdaErrorHandlerResolver, awsLambdaHttpAdapterResolver, awsLambdaHttpErrorHandlerResolver };
export { AWSLambdaAdapter, AWSLambdaHttpAdapter, AWS_LAMBDA_HTTP_PLATFORM, AWS_LAMBDA_PLATFORM, AwsLambda, type AwsLambdaAdapterBlueprint, type AwsLambdaAdapterConfig, type AwsLambdaAdapterContext, AwsLambdaAdapterError, type AwsLambdaAdapterResponseBuilder, type AwsLambdaContext, AwsLambdaErrorHandler, type AwsLambdaErrorHandlerOptions, type AwsLambdaEvent, type AwsLambdaEventHandlerFunction, AwsLambdaHttp, type AwsLambdaHttpAdapterBlueprint, type AwsLambdaHttpAdapterConfig, type AwsLambdaHttpAdapterContext, type AwsLambdaHttpAdapterResponseBuilder, AwsLambdaHttpErrorHandler, type AwsLambdaHttpErrorHandlerOptions, type AwsLambdaHttpEvent, type AwsLambdaHttpOptions, type AwsLambdaOptions, BodyEventMiddleware, FilesEventMiddleware, IncomingEventMiddleware, type RawHttpResponse, type RawHttpResponseOptions, RawHttpResponseWrapper, type RawResponse, RawResponseWrapper, ServerResponseMiddleware, awsLambdaAdapterBlueprint, awsLambdaAdapterResolver, awsLambdaHttpAdapterBlueprint, awsLambdaHttpAdapterResolver };

@@ -1,7 +0,7 @@

import { IntegrationError, Adapter, AdapterEventBuilder, IncomingEvent, ErrorHandler, defaultKernelResolver, defaultLoggerResolver, AdapterHandlerMiddleware, addBlueprint } from '@stone-js/core';
import { IntegrationError, Adapter, AdapterEventBuilder, IncomingEvent, defaultLoggerResolver, defaultKernelResolver, addBlueprint } from '@stone-js/core';
import { IncomingHttpEvent, HTTP_INTERNAL_SERVER_ERROR, CookieCollection, isIpTrusted, getHostname, getProtocol, BinaryFileResponse, isMultipart, getCharset, getType, getFilesUploads } from '@stone-js/http-core';
import mime from 'mime/lite';
import accepts from 'accepts';
import statuses from 'statuses';
import proxyAddr from 'proxy-addr';
import statuses from 'statuses';
import bytes from 'bytes';

@@ -176,2 +176,4 @@ import typeIs from 'type-is';

async eventListener(rawEvent, executionContext) {
const eventHandler = this.handlerResolver(this.blueprint);
await this.onPrepare(eventHandler);
const incomingEventBuilder = AdapterEventBuilder.create({

@@ -184,3 +186,3 @@ resolver: (options) => IncomingEvent.create(options)

const rawResponse = {};
return await this.sendEventThroughDestination({
return await this.sendEventThroughDestination(eventHandler, {
rawEvent,

@@ -359,2 +361,4 @@ rawResponse,

async eventListener(rawEvent, executionContext) {
const eventHandler = this.handlerResolver(this.blueprint);
await this.onPrepare(eventHandler);
const incomingEventBuilder = AdapterEventBuilder.create({

@@ -367,3 +371,3 @@ resolver: (options) => IncomingHttpEvent.create(options)

const rawResponse = { statusCode: 500 };
return await this.sendEventThroughDestination({
return await this.sendEventThroughDestination(eventHandler, {
rawEvent,

@@ -379,2 +383,71 @@ rawResponse,

/**
* Class representing an AwsLambdaErrorHandler.
*/
class AwsLambdaErrorHandler {
logger;
/**
* Create an AwsLambdaErrorHandler.
*
* @param options - AwsLambdaErrorHandler options.
*/
constructor({ logger }) {
if (logger === undefined) {
throw new IntegrationError('Logger is required to create an AwsLambdaErrorHandler instance.');
}
this.logger = logger;
}
/**
* Handle an error.
*
* @param error - The error to handle.
* @param context - The context of the adapter.
* @returns The raw response.
*/
async handle(error, context) {
context
.rawResponseBuilder
.add('statusCode', HTTP_INTERNAL_SERVER_ERROR);
this.logger.error(error.message, { error });
return await context.rawResponseBuilder.build().respond();
}
}
/**
* Class representing an AwsLambdaHttpErrorHandler.
*/
class AwsLambdaHttpErrorHandler {
logger;
/**
* Create an AwsLambdaHttpErrorHandler.
*
* @param options - AwsLambdaHttpErrorHandler options.
*/
constructor({ logger }) {
if (logger === undefined) {
throw new IntegrationError('Logger is required to create an AwsLambdaHttpErrorHandler instance.');
}
this.logger = logger;
}
/**
* Handle an error.
*
* @param error - The error to handle.
* @param context - The context of the adapter.
* @returns The raw response.
*/
async handle(error, context) {
const type = accepts(context.rawEvent).type(['json', 'html']);
const contentType = mime.getType(type !== false ? type : 'txt') ?? 'text/plain';
const headers = new Headers({ 'Content-Type': contentType });
context
.rawResponseBuilder
.add('headers', headers)
.add('statusCode', HTTP_INTERNAL_SERVER_ERROR)
.add('statusMessage', statuses.message[HTTP_INTERNAL_SERVER_ERROR]);
this.logger.error(error.message, { error });
return await context.rawResponseBuilder.build().respond();
}
}
/**
* A constant representing the AWS Lambda platform identifier.

@@ -397,79 +470,2 @@ *

/**
* Resolves and renders an HTTP response for errors in the AWS Lambda HTTP adapter.
*
* This function handles errors by inspecting the error context and generating a
* valid `RawHttpResponse`. It applies default values when necessary and adapts
* the response headers and body to the client's expected content type.
*
* @param error - The error thrown by the AWS Lambda HTTP adapter.
* @returns A `RawHttpResponse` representing the error.
*/
const awsLambdaHttpErrorHandlerRenderResponseResolver = (error) => {
const context = error.metadata;
const rawResponse = context?.rawResponse;
if (context?.rawEvent === undefined || rawResponse === undefined) {
throw new AwsLambdaAdapterError('Invalid error context provided for rendering response.');
}
const httpError = error.cause;
if (httpError?.statusCode !== undefined) {
rawResponse.statusCode = httpError.statusCode;
rawResponse.statusMessage = httpError.statusMessage;
}
else {
rawResponse.statusCode = HTTP_INTERNAL_SERVER_ERROR;
rawResponse.statusMessage = 'Internal Server Error';
}
if (httpError?.headers !== undefined) {
rawResponse.headers = httpError.headers;
}
else {
const type = accepts(context.rawEvent).type(['json', 'html']);
const contentType = mime.getType(type !== false ? type : 'txt') ?? 'text/plain';
rawResponse.headers = { 'Content-Type': contentType };
}
if (httpError?.body !== undefined) {
rawResponse.body = typeof httpError.body === 'string' ? httpError.body : JSON.stringify(httpError.body);
}
return rawResponse;
};
/**
* Resolves a logger for a blueprint.
*
* @param blueprint - The `IBlueprint` to retrieve the logger resolver from.
* @returns A `LoggerResolver` for the given blueprint.
*/
const loggerResolver = (blueprint) => {
return blueprint.get('stone.logger.resolver', defaultLoggerResolver);
};
/**
* Error handler resolver for generic AWS Lambda adapter.
*
* Creates and configures an `ErrorHandler` for managing errors in the generic AWS Lambda adapter.
*
* @param blueprint - The `IBlueprint` providing configuration and dependencies.
* @returns An `ErrorHandler` instance for handling AWS Lambda errors.
*/
const awsLambdaErrorHandlerResolver = (blueprint) => {
return ErrorHandler.create({
blueprint,
logger: loggerResolver(blueprint)(blueprint),
renderResponseResolver: (error) => ({ message: error.message })
});
};
/**
* Error handler resolver for AWS Lambda HTTP adapter.
*
* Creates and configures an `ErrorHandler` for managing errors in the AWS Lambda HTTP adapter.
*
* @param blueprint - The `IBlueprint` providing configuration and dependencies.
* @returns An `ErrorHandler` instance for handling AWS Lambda HTTP errors.
*/
const awsLambdaHttpErrorHandlerResolver = (blueprint) => {
return ErrorHandler.create({
blueprint,
logger: loggerResolver(blueprint)(blueprint),
renderResponseResolver: awsLambdaHttpErrorHandlerRenderResponseResolver
});
};
/**
* Adapter resolver for generic AWS Lambda adapter.

@@ -484,4 +480,4 @@ *

const hooks = blueprint.get('stone.adapter.hooks', {});
const loggerResolver = blueprint.get('stone.logger.resolver', defaultLoggerResolver);
const handlerResolver = blueprint.get('stone.kernel.resolver', defaultKernelResolver);
const errorHandlerResolver = blueprint.get('stone.adapter.errorHandler.resolver', awsLambdaErrorHandlerResolver);
return AWSLambdaAdapter.create({

@@ -491,4 +487,3 @@ hooks,

handlerResolver,
logger: loggerResolver(blueprint)(blueprint),
errorHandler: errorHandlerResolver(blueprint)
logger: loggerResolver(blueprint)
});

@@ -506,4 +501,4 @@ };

const hooks = blueprint.get('stone.adapter.hooks', {});
const loggerResolver = blueprint.get('stone.logger.resolver', defaultLoggerResolver);
const handlerResolver = blueprint.get('stone.kernel.resolver', defaultKernelResolver);
const errorHandlerResolver = blueprint.get('stone.adapter.errorHandler.resolver', awsLambdaHttpErrorHandlerResolver);
return AWSLambdaHttpAdapter.create({

@@ -513,7 +508,154 @@ hooks,

handlerResolver,
logger: loggerResolver(blueprint)(blueprint),
errorHandler: errorHandlerResolver(blueprint)
logger: loggerResolver(blueprint)
});
};
function getDefaultExportFromCjs (x) {
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
}
var cjs;
var hasRequiredCjs;
function requireCjs () {
if (hasRequiredCjs) return cjs;
hasRequiredCjs = 1;
var isMergeableObject = function isMergeableObject(value) {
return isNonNullObject(value)
&& !isSpecial(value)
};
function isNonNullObject(value) {
return !!value && typeof value === 'object'
}
function isSpecial(value) {
var stringValue = Object.prototype.toString.call(value);
return stringValue === '[object RegExp]'
|| stringValue === '[object Date]'
|| isReactElement(value)
}
// see https://github.com/facebook/react/blob/b5ac963fb791d1298e7f396236383bc955f916c1/src/isomorphic/classic/element/ReactElement.js#L21-L25
var canUseSymbol = typeof Symbol === 'function' && Symbol.for;
var REACT_ELEMENT_TYPE = canUseSymbol ? Symbol.for('react.element') : 0xeac7;
function isReactElement(value) {
return value.$$typeof === REACT_ELEMENT_TYPE
}
function emptyTarget(val) {
return Array.isArray(val) ? [] : {}
}
function cloneUnlessOtherwiseSpecified(value, options) {
return (options.clone !== false && options.isMergeableObject(value))
? deepmerge(emptyTarget(value), value, options)
: value
}
function defaultArrayMerge(target, source, options) {
return target.concat(source).map(function(element) {
return cloneUnlessOtherwiseSpecified(element, options)
})
}
function getMergeFunction(key, options) {
if (!options.customMerge) {
return deepmerge
}
var customMerge = options.customMerge(key);
return typeof customMerge === 'function' ? customMerge : deepmerge
}
function getEnumerableOwnPropertySymbols(target) {
return Object.getOwnPropertySymbols
? Object.getOwnPropertySymbols(target).filter(function(symbol) {
return Object.propertyIsEnumerable.call(target, symbol)
})
: []
}
function getKeys(target) {
return Object.keys(target).concat(getEnumerableOwnPropertySymbols(target))
}
function propertyIsOnObject(object, property) {
try {
return property in object
} catch(_) {
return false
}
}
// Protects from prototype poisoning and unexpected merging up the prototype chain.
function propertyIsUnsafe(target, key) {
return propertyIsOnObject(target, key) // Properties are safe to merge if they don't exist in the target yet,
&& !(Object.hasOwnProperty.call(target, key) // unsafe if they exist up the prototype chain,
&& Object.propertyIsEnumerable.call(target, key)) // and also unsafe if they're nonenumerable.
}
function mergeObject(target, source, options) {
var destination = {};
if (options.isMergeableObject(target)) {
getKeys(target).forEach(function(key) {
destination[key] = cloneUnlessOtherwiseSpecified(target[key], options);
});
}
getKeys(source).forEach(function(key) {
if (propertyIsUnsafe(target, key)) {
return
}
if (propertyIsOnObject(target, key) && options.isMergeableObject(source[key])) {
destination[key] = getMergeFunction(key, options)(target[key], source[key], options);
} else {
destination[key] = cloneUnlessOtherwiseSpecified(source[key], options);
}
});
return destination
}
function deepmerge(target, source, options) {
options = options || {};
options.arrayMerge = options.arrayMerge || defaultArrayMerge;
options.isMergeableObject = options.isMergeableObject || isMergeableObject;
// cloneUnlessOtherwiseSpecified is added to `options` so that custom arrayMerge()
// implementations can use it. The caller may not replace it.
options.cloneUnlessOtherwiseSpecified = cloneUnlessOtherwiseSpecified;
var sourceIsArray = Array.isArray(source);
var targetIsArray = Array.isArray(target);
var sourceAndTargetTypesMatch = sourceIsArray === targetIsArray;
if (!sourceAndTargetTypesMatch) {
return cloneUnlessOtherwiseSpecified(source, options)
} else if (sourceIsArray) {
return options.arrayMerge(target, source, options)
} else {
return mergeObject(target, source, options)
}
}
deepmerge.all = function deepmergeAll(array, options) {
if (!Array.isArray(array)) {
throw new Error('first argument should be an array')
}
return array.reduce(function(prev, next) {
return deepmerge(prev, next, options)
}, {})
};
var deepmerge_1 = deepmerge;
cjs = deepmerge_1;
return cjs;
}
var cjsExports = requireCjs();
var deepmerge = /*@__PURE__*/getDefaultExportFromCjs(cjsExports);
/**

@@ -528,3 +670,3 @@ * Default blueprint configuration for the AWS Lambda Adapter.

*/
const awsLambaAdapterBlueprint = {
const awsLambdaAdapterBlueprint = {
stone: {

@@ -535,12 +677,9 @@ adapters: [

resolver: awsLambdaAdapterResolver,
middleware: [
{ priority: 100, pipe: AdapterHandlerMiddleware }
],
middleware: [],
hooks: {},
errorHandler: {
resolver: awsLambdaErrorHandlerResolver
errorHandlers: {
default: AwsLambdaErrorHandler
},
current: false,
default: false,
preferred: false
default: false
}

@@ -565,6 +704,6 @@ ]

* ```typescript
* import { AwsLambdaAdapter } from '@stone-js/aws-lambda-adapter';
* import { AwsLambda } from '@stone-js/aws-lambda-adapter';
*
* @AwsLambdaAdapter({
* alias: 'MyAWSLambdaAdapter',
* @AwsLambda({
* alias: 'MyAWSLambda',
* })

@@ -576,13 +715,10 @@ * class App {

*/
const AwsLambdaAdapter = (options = {}) => {
const AwsLambda = (options = {}) => {
return (target, context) => {
if (awsLambaAdapterBlueprint.stone?.adapters?.[0] !== undefined) {
if (awsLambdaAdapterBlueprint.stone?.adapters?.[0] !== undefined) {
// Merge provided options with the default AWS Lambda adapter blueprint.
awsLambaAdapterBlueprint.stone.adapters[0] = {
...awsLambaAdapterBlueprint.stone.adapters[0],
...options
};
awsLambdaAdapterBlueprint.stone.adapters[0] = deepmerge(awsLambdaAdapterBlueprint.stone.adapters[0], options);
}
// Add the modified blueprint to the target class.
addBlueprint(target, context, awsLambaAdapterBlueprint);
addBlueprint(target, context, awsLambdaAdapterBlueprint);
};

@@ -743,14 +879,2 @@ };

/**
* The blueprint for resolving configuration and dependencies.
*/
blueprint;
/**
* Create a ServerResponseMiddleware.
*
* @param {blueprint} options - Options for creating the ServerResponseMiddleware.
*/
constructor({ blueprint }) {
this.blueprint = blueprint;
}
/**
* Handles the outgoing response, processes it, and invokes the next middleware in the pipeline.

@@ -760,11 +884,11 @@ *

* @param next - The next middleware to be invoked in the pipeline.
* @returns A promise resolving to the processed context.
* @returns A promise resolving to the rawResponseBuilder.
* @throws {AwsLambdaAdapterError} If required components are missing in the context.
*/
async handle(context, next) {
if (context.rawEvent === undefined || context.incomingEvent === undefined || context.outgoingResponse === undefined || context.rawResponseBuilder?.add === undefined) {
const rawResponseBuilder = await next(context);
if (context.rawEvent === undefined || context.incomingEvent === undefined || context.outgoingResponse === undefined || rawResponseBuilder?.add === undefined) {
throw new AwsLambdaAdapterError('The context is missing required components.');
}
context
.rawResponseBuilder
rawResponseBuilder
.add('headers', context.outgoingResponse.headers)

@@ -775,9 +899,7 @@ .add('statusCode', context.outgoingResponse.statusCode ?? 500)

if (context.outgoingResponse instanceof BinaryFileResponse) {
context
.rawResponseBuilder
rawResponseBuilder
.add('body', context.outgoingResponse.file.getContent());
}
else {
context
.rawResponseBuilder
rawResponseBuilder
.add('body', context.outgoingResponse.content)

@@ -787,3 +909,3 @@ .add('charset', context.outgoingResponse.charset);

}
return await next(context);
return rawResponseBuilder;
}

@@ -801,3 +923,3 @@ }

*/
const awsLambaHttpAdapterBlueprint = {
const awsLambdaHttpAdapterBlueprint = {
stone: {

@@ -810,12 +932,10 @@ adapters: [

{ priority: 0, pipe: IncomingEventMiddleware },
{ priority: 100, pipe: AdapterHandlerMiddleware },
{ priority: 200, pipe: ServerResponseMiddleware }
{ priority: 10, pipe: ServerResponseMiddleware }
],
hooks: {},
errorHandler: {
resolver: awsLambdaHttpErrorHandlerResolver
errorHandlers: {
default: AwsLambdaHttpErrorHandler
},
current: false,
default: false,
preferred: false
default: false
}

@@ -840,5 +960,5 @@ ]

* ```typescript
* import { AwsLambdaHttpAdapter } from '@stone-js/aws-lambda-adapter';
* import { AwsLambdaHttp } from '@stone-js/aws-lambda-adapter';
*
* @AwsLambdaHttpAdapter({
* @AwsLambdaHttp({
* alias: 'MyAwsLambdaHttpAdapter',

@@ -852,13 +972,10 @@ * current: true,

*/
const AwsLambdaHttpAdapter = (options = {}) => {
const AwsLambdaHttp = (options = {}) => {
return (target, context) => {
if (awsLambaHttpAdapterBlueprint.stone?.adapters?.[0] !== undefined) {
if (awsLambdaHttpAdapterBlueprint.stone?.adapters?.[0] !== undefined) {
// Merge provided options with the default AWS Lambda HTTP adapter blueprint.
awsLambaHttpAdapterBlueprint.stone.adapters[0] = {
...awsLambaHttpAdapterBlueprint.stone.adapters[0],
...options
};
awsLambdaHttpAdapterBlueprint.stone.adapters[0] = deepmerge(awsLambdaHttpAdapterBlueprint.stone.adapters[0], options);
}
// Add the modified blueprint to the target class.
addBlueprint(target, context, awsLambaHttpAdapterBlueprint);
addBlueprint(target, context, awsLambdaHttpAdapterBlueprint);
};

@@ -1004,2 +1121,2 @@ };

export { AWSLambdaAdapter, AWSLambdaHttpAdapter, AWS_LAMBDA_HTTP_PLATFORM, AWS_LAMBDA_PLATFORM, AwsLambdaAdapter, AwsLambdaAdapterError, AwsLambdaHttpAdapter, BodyEventMiddleware, FilesEventMiddleware, IncomingEventMiddleware, RawHttpResponseWrapper, RawResponseWrapper, ServerResponseMiddleware, awsLambaAdapterBlueprint, awsLambaHttpAdapterBlueprint, awsLambdaAdapterResolver, awsLambdaErrorHandlerResolver, awsLambdaHttpAdapterResolver, awsLambdaHttpErrorHandlerResolver };
export { AWSLambdaAdapter, AWSLambdaHttpAdapter, AWS_LAMBDA_HTTP_PLATFORM, AWS_LAMBDA_PLATFORM, AwsLambda, AwsLambdaAdapterError, AwsLambdaErrorHandler, AwsLambdaHttp, AwsLambdaHttpErrorHandler, BodyEventMiddleware, FilesEventMiddleware, IncomingEventMiddleware, RawHttpResponseWrapper, RawResponseWrapper, ServerResponseMiddleware, awsLambdaAdapterBlueprint, awsLambdaAdapterResolver, awsLambdaHttpAdapterBlueprint, awsLambdaHttpAdapterResolver };
{
"name": "@stone-js/aws-lambda-adapter",
"version": "0.0.2",
"version": "0.0.22",
"description": "Stone.js AWS Lambda Adapters",

@@ -59,6 +59,6 @@ "author": "Mr. Stone <evensstone@gmail.com>",

"peerDependencies": {
"@stone-js/core": "^0.0.35",
"@stone-js/http-core": "^0.0.33",
"@stone-js/core": "^0.0.36",
"@stone-js/pipeline": "^0.0.46",
"@stone-js/service-container": "^0.0.43"
"@stone-js/http-core": "^0.0.34",
"@stone-js/service-container": "^0.0.44"
},

@@ -75,5 +75,5 @@ "dependencies": {

"devDependencies": {
"@commitlint/cli": "^19.5.0",
"@commitlint/config-conventional": "^19.5.0",
"@rollup/plugin-commonjs": "^25.0.7",
"@commitlint/cli": "^19.6.1",
"@commitlint/config-conventional": "^19.6.0",
"@rollup/plugin-commonjs": "^28.0.2",
"@rollup/plugin-multi-entry": "^6.0.1",

@@ -92,11 +92,11 @@ "@rollup/plugin-node-resolve": "^15.2.3",

"husky": "^9.1.6",
"rimraf": "^5.0.5",
"rimraf": "^6.0.1",
"rollup": "^4.1.5",
"rollup-plugin-delete": "^2.1.0",
"rollup-plugin-dts": "^6.1.1",
"rollup-plugin-node-externals": "^6.1.2",
"rollup-plugin-node-externals": "^8.0.0",
"ts-standard": "^12.0.2",
"tslib": "^2.8.1",
"typedoc": "^0.27.0",
"typedoc-plugin-markdown": "^4.2.10",
"typedoc": "^0.27.6",
"typedoc-plugin-markdown": "^4.4.1",
"typescript": "^5.6.3",

@@ -103,0 +103,0 @@ "vitest": "^2.1.4"

@@ -6,5 +6,5 @@ # Stone.js: AWS Lambda Adapters

[![npm](https://img.shields.io/npm/dm/@stone-js/aws-lambda-adapter)](https://www.npmjs.com/package/@stone-js/aws-lambda-adapter)
![Maintenance](https://img.shields.io/maintenance/yes/2024)
![Maintenance](https://img.shields.io/maintenance/yes/2025)
[![Publish Package to npmjs](https://github.com/stonemjs/aws-lambda-adapter/actions/workflows/release.yml/badge.svg)](https://github.com/stonemjs/aws-lambda-adapter/actions/workflows/release.yml)
[![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=stonemjs/aws-lambda-adapter)](https://dependabot.com)
[![Dependabot Status](https://img.shields.io/badge/Dependabot-enabled-brightgreen.svg?logo=dependabot)](https://github.com/stonemjs/aws-lambda-adapter/network/updates)
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)

@@ -11,0 +11,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc