UNPKG

@h4ad/serverless-adapter

Version:

Run REST APIs and other web applications using your existing Node.js application framework (NestJS, Express, Koa, Hapi, Fastify and many others), on top of AWS, Azure, Digital Ocean and many other clouds.

935 lines (922 loc) 34.2 kB
import { ALBEvent, Context, ALBResult, APIGatewayProxyResult, APIGatewayProxyEventV2, SQSBatchItemFailure, DynamoDBStreamEvent, EventBridgeEvent, CloudFrontRequest, S3Event, SNSEvent, SQSEvent } from 'aws-lambda'; import { A as AdapterContract, a as AdapterRequest, G as GetResponseAdapterProps, O as OnErrorProps } from '../../adapter.contract-Cp2Jsh5V.cjs'; import { S as StripBasePathFn, C as Concrete } from '../../path-BrSXm7S6.cjs'; import { APIGatewayProxyEvent, APIGatewayProxyStructuredResultV2 } from 'aws-lambda/trigger/api-gateway-proxy'; import { I as IEmptyResponse } from '../../constants-DVTIV7Xu.cjs'; import { CloudFrontHeaders, CloudFrontEvent, CloudFrontResultResponse } from 'aws-lambda/common/cloudfront'; import { CloudFrontRequestEvent, CloudFrontRequestResult } from 'aws-lambda/trigger/cloudfront-request'; import { S as SingleValueHeaders, B as BothValueHeaders } from '../../headers-DjfGHDmI.cjs'; import 'http'; import 'node:http'; import '../../logger-F8qccesk.cjs'; /** * The options to customize the {@link AlbAdapter} * * @breadcrumb Adapters / AWS / AlbAdapter * @public */ interface AlbAdapterOptions { /** * Strip base path for custom domains * * @defaultValue '' */ stripBasePath?: string; } /** * The adapter to handle requests from AWS ALB * * @example * ```typescript * const stripBasePath = '/any/custom/base/path'; // default '' * const adapter = new AlbAdapter({ stripBasePath }); * ``` * * {@link https://docs.aws.amazon.com/lambda/latest/dg/services-alb.html | Event Reference} * * @breadcrumb Adapters / AWS / AlbAdapter * @public */ declare class AlbAdapter implements AdapterContract<ALBEvent, Context, ALBResult> { protected readonly options?: AlbAdapterOptions | undefined; /** * Default constructor * * @param options - The options to customize the {@link AlbAdapter} */ constructor(options?: AlbAdapterOptions | undefined); /** * Strip base path function */ protected stripPathFn: StripBasePathFn; /** * {@inheritDoc} */ getAdapterName(): string; /** * {@inheritDoc} */ canHandle(event: unknown): event is ALBEvent; /** * {@inheritDoc} */ getRequest(event: ALBEvent): AdapterRequest; /** * {@inheritDoc} */ getResponse({ event, headers: responseHeaders, body, isBase64Encoded, statusCode, }: GetResponseAdapterProps<ALBEvent>): ALBResult; /** * {@inheritDoc} */ onErrorWhileForwarding({ error, delegatedResolver, respondWithErrors, event, log, }: OnErrorProps<ALBEvent, ALBResult>): void; /** * Get path from event with query strings * * @param event - The event sent by serverless */ protected getPathFromEvent(event: ALBEvent): string; } /** * The options to customize the {@link ApiGatewayV1Adapter} * * @breadcrumb Adapters / AWS / ApiGatewayV1Adapter * @public */ interface ApiGatewayV1Options { /** * Strip base path for custom domains * * @defaultValue '' */ stripBasePath?: string; /** * Throw an exception when you send the `transfer-encoding=chunked`, currently, API Gateway doesn't support chunked transfer. * If this is set to `false`, we will remove the `transfer-encoding` header from the response and buffer the response body * while we remove the special characters inserted by the chunked encoding. * * @remarks To learn more https://github.com/H4ad/serverless-adapter/issues/165 * @defaultValue true */ throwOnChunkedTransferEncoding?: boolean; /** * Emulates the behavior of Node.js `http` module by ensuring all request headers are lowercase. * * @defaultValue false */ lowercaseRequestHeaders?: boolean; } /** * The adapter to handle requests from AWS Api Gateway V1 * * As per {@link https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-known-issues.html | know issues}, we throw an exception when you send the `transfer-encoding=chunked`, currently, API Gateway doesn't support chunked transfer. * * @remarks This adapter is not fully compatible with \@vendia/serverless-express, on \@vendia they filter `transfer-encoding=chunked` but we throw an exception. * * @example * ```typescript * const stripBasePath = '/any/custom/base/path'; // default '' * const adapter = new ApiGatewayV1Adapter({ stripBasePath }); * ``` * * {@link https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html | Event Reference} * * @breadcrumb Adapters / AWS / ApiGatewayV1Adapter * @public */ declare class ApiGatewayV1Adapter implements AdapterContract<APIGatewayProxyEvent, Context, APIGatewayProxyResult> { protected readonly options?: ApiGatewayV1Options | undefined; /** * Default constructor * * @param options - The options to customize the {@link ApiGatewayV1Adapter} */ constructor(options?: ApiGatewayV1Options | undefined); /** * Strip base path function */ protected stripPathFn: StripBasePathFn; /** * {@inheritDoc} */ getAdapterName(): string; /** * {@inheritDoc} */ canHandle(event: unknown): event is APIGatewayProxyEvent; /** * {@inheritDoc} */ getRequest(event: APIGatewayProxyEvent): AdapterRequest; /** * {@inheritDoc} */ getResponse({ headers: responseHeaders, body, isBase64Encoded, statusCode, response, }: GetResponseAdapterProps<APIGatewayProxyEvent>): APIGatewayProxyResult; /** * {@inheritDoc} */ onErrorWhileForwarding({ error, delegatedResolver, respondWithErrors, event, log, }: OnErrorProps<APIGatewayProxyEvent, APIGatewayProxyResult>): void; /** * Get path from event with query strings * * @param event - The event sent by serverless */ protected getPathFromEvent(event: APIGatewayProxyEvent): string; } /** * The options to customize the {@link ApiGatewayV2Adapter} * * @breadcrumb Adapters / AWS / ApiGatewayV2Adapter * @public */ interface ApiGatewayV2Options { /** * Strip base path for custom domains * * @defaultValue '' */ stripBasePath?: string; /** * Throw an exception when you send the `transfer-encoding=chunked`, currently, API Gateway doesn't support chunked transfer. * If this is set to `false`, we will remove the `transfer-encoding` header from the response and buffer the response body * while we remove the special characters inserted by the chunked encoding. * * @remarks To learn more https://github.com/H4ad/serverless-adapter/issues/165 * @defaultValue true */ throwOnChunkedTransferEncoding?: boolean; } /** * The adapter to handle requests from AWS Api Gateway V2 * * As per {@link https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-known-issues.html | know issues}, we throw an exception when you send the `transfer-encoding=chunked`. * But, if you use this adapter to accept requests from Function URL, you can accept the `transfer-encoding=chunked` changing the method of invocation from `BUFFERED` to `RESPONSE_STREAM`. * * @example * ```typescript * const stripBasePath = '/any/custom/base/path'; // default '' * const adapter = new ApiGatewayV2Adapter({ stripBasePath }); * ``` * * {@link https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html | Event Reference} * * @breadcrumb Adapters / AWS / ApiGatewayV2Adapter * @public */ declare class ApiGatewayV2Adapter implements AdapterContract<APIGatewayProxyEventV2, Context, APIGatewayProxyStructuredResultV2> { protected readonly options?: ApiGatewayV2Options | undefined; /** * Default constructor * * @param options - The options to customize the {@link ApiGatewayV2Adapter} */ constructor(options?: ApiGatewayV2Options | undefined); /** * Strip base path function */ protected stripPathFn: StripBasePathFn; /** * {@inheritDoc} */ getAdapterName(): string; /** * {@inheritDoc} */ canHandle(event: unknown): event is APIGatewayProxyEventV2; /** * {@inheritDoc} */ getRequest(event: APIGatewayProxyEventV2): AdapterRequest; /** * {@inheritDoc} */ getResponse({ headers: responseHeaders, body, isBase64Encoded, statusCode, response, }: GetResponseAdapterProps<APIGatewayProxyEventV2>): APIGatewayProxyStructuredResultV2; /** * {@inheritDoc} */ onErrorWhileForwarding({ error, delegatedResolver, respondWithErrors, event, log, }: OnErrorProps<APIGatewayProxyEventV2, APIGatewayProxyStructuredResultV2>): void; /** * Get path from event with query strings * * @param event - The event sent by serverless */ protected getPathFromEvent(event: APIGatewayProxyEventV2): string; } /** * The options to customize the {@link AwsSimpleAdapter} * * @breadcrumb Adapters / AWS / AWS Simple Adapter * @public */ interface AWSSimpleAdapterOptions { /** * The path that will be used to create a request to be forwarded to the framework. */ forwardPath: string; /** * The http method that will be used to create a request to be forwarded to the framework. */ forwardMethod: string; /** * The AWS Service host that will be injected inside headers to developer being able to validate if request originate from the library. */ host: string; /** * Tells if this adapter should support batch item failures. */ batch?: true | false; } /** * The batch item failure response expected from the API server * * @breadcrumb Adapters / AWS / AWS Simple Adapter * @public */ type BatchItemFailureResponse = SQSBatchItemFailure; /** * The possible options of response for {@link AwsSimpleAdapter} * * @breadcrumb Adapters / AWS / AWS Simple Adapter * @public */ type AWSSimpleAdapterResponseType = BatchItemFailureResponse | IEmptyResponse; /** * The abstract adapter to use to implement other simple AWS adapters * * @breadcrumb Adapters / AWS / AWS Simple Adapter * @public */ declare abstract class AwsSimpleAdapter<TEvent> implements AdapterContract<TEvent, Context, AWSSimpleAdapterResponseType> { protected readonly options: AWSSimpleAdapterOptions; /** * Default constructor * * @param options - The options to customize the {@link AwsSimpleAdapter} */ constructor(options: AWSSimpleAdapterOptions); /** * {@inheritDoc} */ getAdapterName(): string; /** * {@inheritDoc} */ canHandle(_: unknown): _ is TEvent; /** * {@inheritDoc} */ getRequest(event: TEvent): AdapterRequest; /** * {@inheritDoc} */ getResponse({ body, headers, isBase64Encoded, event, statusCode, }: GetResponseAdapterProps<TEvent>): AWSSimpleAdapterResponseType; /** * {@inheritDoc} */ onErrorWhileForwarding({ error, delegatedResolver, }: OnErrorProps<TEvent, AWSSimpleAdapterResponseType>): void; /** * Check if the status code is invalid * * @param statusCode - The status code */ protected hasInvalidStatusCode(statusCode: number): boolean; } /** * The options to customize the {@link DynamoDBAdapter} * * @breadcrumb Adapters / AWS / DynamoDBAdapter * @public */ interface DynamoDBAdapterOptions extends Pick<AWSSimpleAdapterOptions, 'batch'> { /** * The path that will be used to create a request to be forwarded to the framework. * * @defaultValue /dynamo */ dynamoDBForwardPath?: string; /** * The http method that will be used to create a request to be forwarded to the framework. * * @defaultValue POST */ dynamoDBForwardMethod?: string; } /** * The adapter to handle requests from AWS DynamoDB. * * The option of `responseWithErrors` is ignored by this adapter and we always call `resolver.fail` with the error. * * {@link https://docs.aws.amazon.com/lambda/latest/dg/with-ddb.html | Event Reference} * * @example * ```typescript * const dynamoDBForwardPath = '/your/route/dynamo'; // default /dynamo * const dynamoDBForwardMethod = 'POST'; // default POST * const adapter = new DynamoDBAdapter({ dynamoDBForwardPath, dynamoDBForwardMethod }); * ``` * * @breadcrumb Adapters / AWS / DynamoDBAdapter * @public */ declare class DynamoDBAdapter extends AwsSimpleAdapter<DynamoDBStreamEvent> { /** * Default constructor * * @param options - The options to customize the {@link DynamoDBAdapter} */ constructor(options?: DynamoDBAdapterOptions); /** * {@inheritDoc} */ getAdapterName(): string; /** * {@inheritDoc} */ canHandle(event: unknown): event is DynamoDBStreamEvent; } /** * The options to customize the {@link EventBridgeAdapter} * * @breadcrumb Adapters / AWS / EventBridgeAdapter * @public */ interface EventBridgeOptions { /** * The path that will be used to create a request to be forwarded to the framework. * * @defaultValue /eventbridge */ eventBridgeForwardPath?: string; /** * The http method that will be used to create a request to be forwarded to the framework. * * @defaultValue POST */ eventBridgeForwardMethod?: string; } /** * Just a type alias to ignore generic types in the event * * @breadcrumb Adapters / AWS / EventBridgeAdapter * @public */ type EventBridgeEventAll = EventBridgeEvent<any, any>; /** * The adapter to handle requests from AWS EventBridge (Cloudwatch Events). * * The option of `responseWithErrors` is ignored by this adapter and we always call `resolver.fail` with the error. * * {@link https://docs.aws.amazon.com/lambda/latest/dg/services-cloudwatchevents.html | Event Reference} * * @example * ```typescript * const eventBridgeForwardPath = '/your/route/eventbridge'; // default /eventbridge * const eventBridgeForwardMethod = 'POST'; // default POST * const adapter = new EventBridgeAdapter({ eventBridgeForwardPath, eventBridgeForwardMethod }); * ``` * * @breadcrumb Adapters / AWS / EventBridgeAdapter * @public */ declare class EventBridgeAdapter extends AwsSimpleAdapter<EventBridgeEventAll> { /** * Default constructor * * @param options - The options to customize the {@link EventBridgeAdapter} */ constructor(options?: EventBridgeOptions); /** * {@inheritDoc} */ getAdapterName(): string; /** * {@inheritDoc} */ canHandle(event: unknown): event is EventBridgeEventAll; } /** * The type alias to indicate where we get the default value of query string to create the request. * * @breadcrumb Adapters / AWS / LambdaEdgeAdapter * @public */ type DefaultQueryString = CloudFrontRequestEvent['Records'][number]['cf']['request']['querystring']; /** * The type alias to indicate where we get the default value of path to create the request. * * @breadcrumb Adapters / AWS / LambdaEdgeAdapter * @public */ type DefaultForwardPath = CloudFrontRequestEvent['Records'][number]['cf']['request']['uri']; /** * Represents the body of the new version of Lambda\@edge, which uses the `body` property inside `request` as the body (library) of the request. * * @breadcrumb Adapters / AWS / LambdaEdgeAdapter * @public */ type NewLambdaEdgeBody = CloudFrontRequestEvent['Records'][number]['cf']['request']['body']; /** * Represents the body of the old version of Lambda\@edge supported by \@vendia/serverless-express which returns the `data` property within `body` for the body (library) of the request. * * @breadcrumb Adapters / AWS / LambdaEdgeAdapter * @public */ type OldLambdaEdgeBody = Concrete<CloudFrontRequestEvent['Records'][number]['cf']['request']>['body']['data']; /** * The list was created based on {@link https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/edge-functions-restrictions.html | these docs} in the "Disallowed Headers" section. * * @breadcrumb Adapters / AWS / LambdaEdgeAdapter / Constants * @public */ declare const DEFAULT_LAMBDA_EDGE_DISALLOWED_HEADERS: (string | RegExp)[]; /** * The default max response size in bytes of viewer request and viewer response. * * @defaultValue 1024 * 40 = 40960 = 40KB * * {@link https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html | Reference} * * @breadcrumb Adapters / AWS / LambdaEdgeAdapter / Constants * @public */ declare const DEFAULT_VIEWER_MAX_RESPONSE_SIZE_IN_BYTES: number; /** * The default max response size in bytes of origin request and origin response. * * @defaultValue 1024 * 1024 = 1048576 = 1MB * * {@link https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html | Reference} * * @breadcrumb Adapters / AWS / LambdaEdgeAdapter / Constants * @public */ declare const DEFAULT_ORIGIN_MAX_RESPONSE_SIZE_IN_BYTES: number; /** * The options to customize the {@link LambdaEdgeAdapter}. * * @breadcrumb Adapters / AWS / LambdaEdgeAdapter * @public */ interface LambdaEdgeAdapterOptions { /** * The max response size in bytes of viewer request and viewer response. * * {@link https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html | Reference} * * @defaultValue {@link DEFAULT_VIEWER_MAX_RESPONSE_SIZE_IN_BYTES} */ viewerMaxResponseSizeInBytes?: number; /** * The max response size in bytes of origin request and origin response. * * {@link https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html | Reference} * * @defaultValue {@link DEFAULT_ORIGIN_MAX_RESPONSE_SIZE_IN_BYTES} */ originMaxResponseSizeInBytes?: number; /** * The function called when the response size exceed the max limits of the Lambda\@edge * * @param response - The response from framework that exceed the limit of Lambda\@edge * @defaultValue undefined */ onResponseSizeExceedLimit?: (response: CloudFrontRequestResult) => CloudFrontRequestResult; /** * Return the path to be used to create a request to the framework * * @remarks You MUST append the query params from {@link DefaultQueryString}, you can use the helper {@link getPathWithQueryStringParams}. * * @param event - The event sent by the serverless * @defaultValue The value from {@link DefaultForwardPath} */ getPathFromEvent?: (event: CloudFrontRequestEvent['Records'][number]) => string; /** * The headers that will be stripped from the headers object because Lambda\@edge will fail if these headers are passed in the response. * * @remarks All headers will be compared with other headers using toLowerCase, but for the RegExp, if you modify this list, you must put the flag `/gmi` at the end of the RegExp (ex: `/(X-Amz-Cf-)(.*)/gim`) * * @defaultValue To get the full list, see {@link DEFAULT_LAMBDA_EDGE_DISALLOWED_HEADERS}. */ disallowedHeaders?: (string | RegExp)[]; /** * If you want to change how we check against the header if it should be stripped, you can pass a function to this property. * * @param header - The header of the response * @defaultValue The default method is implemented to test the header against the list {@link LambdaEdgeAdapterOptions.disallowedHeaders}. */ shouldStripHeader?: (header: string) => boolean; /** * By default, the {@link aws-lambda#CloudFrontRequestResult} has the `headers` property, but we also have the headers sent by the framework too. * So this setting tells us how to handle this case, if you pass `true` to this property, we will use the framework headers. * Otherwise, we will forward the body back to cloudfront without modifying or trying to set the `headers` property inside {@link aws-lambda#CloudFrontRequestResult}. * * @defaultValue false */ shouldUseHeadersFromFramework?: boolean; } /** * The adapter to handle requests from AWS Lambda\@Edge. * * This adapter is not fully compatible with Lambda\@edge supported by \@vendia/serverless-express, the request body was modified to return {@link NewLambdaEdgeBody} instead {@link OldLambdaEdgeBody}. * Also, the response has been modified to return entire body sent by the framework, in this form you MUST return the body from the framework in the format of {@link aws-lambda#CloudFrontRequestResult}. * And when we get an error during the forwarding to the framework, we call `resolver.fail` instead of trying to return status 500 like the old implementation was. * * {@link https://docs.aws.amazon.com/lambda/latest/dg/lambda-edge.html | Lambda edge docs} * {@link https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-event-structure.html | Event Reference} * * @example * ```typescript * const getPathFromEvent = () => '/lambda/edge'; // will forward all requests to the same endpoint * const adapter = new LambdaEdgeAdapter({ getPathFromEvent }); * ``` * * @breadcrumb Adapters / AWS / LambdaEdgeAdapter * @public */ declare class LambdaEdgeAdapter implements AdapterContract<CloudFrontRequestEvent, Context, CloudFrontRequestResult> { protected readonly options?: LambdaEdgeAdapterOptions | undefined; /** * Default constructor * * @param options - The options to customize the {@link LambdaEdgeAdapter} */ constructor(options?: LambdaEdgeAdapterOptions | undefined); /** * This property is used to cache the disallowed headers in `RegExp` version, even if you provide a string in `disallowedHeader`, we will cache it in an instance of `RegExp`. */ protected readonly cachedDisallowedHeaders: RegExp[]; /** * {@inheritDoc} */ getAdapterName(): string; /** * {@inheritDoc} */ canHandle(event: unknown): event is CloudFrontRequestEvent; /** * {@inheritDoc} */ getRequest(event: CloudFrontRequestEvent): AdapterRequest; /** * {@inheritDoc} */ getResponse(props: GetResponseAdapterProps<CloudFrontRequestEvent>): CloudFrontRequestResult; /** * {@inheritDoc} */ onErrorWhileForwarding({ error, delegatedResolver, }: OnErrorProps<CloudFrontRequestEvent, CloudFrontRequestResult>): void; /** * Returns the headers with the flattened (non-list) values of the cloudfront request headers * * @param cloudFrontRequest - The cloudfront request */ protected getFlattenedHeadersFromCloudfrontRequest(cloudFrontRequest: CloudFrontRequest): SingleValueHeaders; /** * Returns the framework response in the format required by the Lambda\@edge. * * @param body - The body of the response * @param frameworkHeaders - The headers from the framework */ protected getResponseToLambdaEdge({ body, headers: frameworkHeaders, }: GetResponseAdapterProps<CloudFrontRequestEvent>): CloudFrontRequestResult; /** * Returns headers in Cloudfront Response format. * * @param originalHeaders - The original version of the request sent by the framework */ protected getHeadersForCloudfrontResponse(originalHeaders: BothValueHeaders): CloudFrontHeaders; /** * Returns the information if we should remove the response header * * @param headerKey - The header that will be tested */ protected shouldStripHeader(headerKey: string): boolean; /** * Determines whether the event is from origin or is from viewer. * * @param content - The event sent by AWS or the response sent by the framework */ protected isEventTypeOrigin(content: CloudFrontEvent['config']): boolean; } /** * The options to customize the {@link S3Adapter} * * @breadcrumb Adapters / AWS / S3Adapter * @public */ interface S3AdapterOptions { /** * The path that will be used to create a request to be forwarded to the framework. * * @defaultValue /s3 */ s3ForwardPath?: string; /** * The http method that will be used to create a request to be forwarded to the framework. * * @defaultValue POST */ s3ForwardMethod?: string; } /** * The adapter to handle requests from AWS S3. * * The option of `responseWithErrors` is ignored by this adapter and we always call `resolver.fail` with the error. * * {@link https://docs.aws.amazon.com/lambda/latest/dg/with-s3.html | Event Reference} * * @example * ```typescript * const s3ForwardPath = '/your/route/s3'; // default /s3 * const s3ForwardMethod = 'POST'; // default POST * const adapter = new S3Adapter({ s3ForwardPath, s3ForwardMethod }); * ``` * * @breadcrumb Adapters / AWS / S3Adapter * @public */ declare class S3Adapter extends AwsSimpleAdapter<S3Event> { /** * Default constructor * * @param options - The options to customize the {@link SNSAdapter} */ constructor(options?: S3AdapterOptions); /** * {@inheritDoc} */ getAdapterName(): string; /** * {@inheritDoc} */ canHandle(event: unknown): event is S3Event; } /** * The options to customize the {@link SNSAdapter} * * @breadcrumb Adapters / AWS / SNSAdapter * @public */ interface SNSAdapterOptions { /** * The path that will be used to create a request to be forwarded to the framework. * * @defaultValue /sns */ snsForwardPath?: string; /** * The http method that will be used to create a request to be forwarded to the framework. * * @defaultValue POST */ snsForwardMethod?: string; } /** * The adapter to handle requests from AWS SNS. * * The option of `responseWithErrors` is ignored by this adapter and we always call `resolver.fail` with the error. * * {@link https://docs.aws.amazon.com/lambda/latest/dg/with-sns.html | Event Reference} * * @example * ```typescript * const snsForwardPath = '/your/route/sns'; // default /sns * const snsForwardMethod = 'POST'; // default POST * const adapter = new SNSAdapter({ snsForwardPath, snsForwardMethod }); * ``` * * @breadcrumb Adapters / AWS / SNSAdapter * @public */ declare class SNSAdapter extends AwsSimpleAdapter<SNSEvent> { /** * Default constructor * * @param options - The options to customize the {@link SNSAdapter} */ constructor(options?: SNSAdapterOptions); /** * {@inheritDoc} */ getAdapterName(): string; /** * {@inheritDoc} */ canHandle(event: unknown): event is SNSEvent; } /** * The options to customize the {@link SQSAdapter} * * @breadcrumb Adapters / AWS / SQSAdapter * @public */ interface SQSAdapterOptions extends Pick<AWSSimpleAdapterOptions, 'batch'> { /** * The path that will be used to create a request to be forwarded to the framework. * * @defaultValue /sqs */ sqsForwardPath?: string; /** * The http method that will be used to create a request to be forwarded to the framework. * * @defaultValue POST */ sqsForwardMethod?: string; } /** * The adapter to handle requests from AWS SQS. * * The option of `responseWithErrors` is ignored by this adapter and we always call `resolver.fail` with the error. * * {@link https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html | Event Reference} * * @example * ```typescript * const sqsForwardPath = '/your/route/sqs'; // default /sqs * const sqsForwardMethod = 'POST'; // default POST * const adapter = new SQSAdapter({ sqsForwardPath, sqsForwardMethod }); * ``` * * @breadcrumb Adapters / AWS / SQSAdapter * @public */ declare class SQSAdapter extends AwsSimpleAdapter<SQSEvent> { /** * Default constructor * * @param options - The options to customize the {@link SNSAdapter} */ constructor(options?: SQSAdapterOptions); /** * {@inheritDoc} */ getAdapterName(): string; /** * {@inheritDoc} */ canHandle(event: unknown): event is SQSEvent; } /** * The options to customize the {@link RequestLambdaEdgeAdapter}. * * @breadcrumb Adapters / AWS / RequestLambdaEdgeAdapter * @public */ interface RequestLambdaEdgeAdapterOptions { /** * Strip base path for custom paths, like `/api`. * * @defaultValue '' */ stripBasePath?: string; /** * The max response size in bytes of viewer request and viewer response. * * {@link https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html | Reference} * * @defaultValue {@link DEFAULT_VIEWER_MAX_RESPONSE_SIZE_IN_BYTES} */ viewerMaxResponseSizeInBytes?: number; /** * The max response size in bytes of origin request and origin response. * * {@link https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html | Reference} * * @defaultValue {@link DEFAULT_ORIGIN_MAX_RESPONSE_SIZE_IN_BYTES} */ originMaxResponseSizeInBytes?: number; /** * The function called when the response size exceed the max limits of the Lambda\@edge * * @param response - The response from framework that exceed the limit of Lambda\@edge * @defaultValue undefined */ onResponseSizeExceedLimit?: (response: CloudFrontRequestResult) => CloudFrontRequestResult; /** * The headers that will be stripped from the headers object because Lambda\@edge will fail if these headers are passed in the response. * * @remarks All headers will be compared with other headers using toLowerCase, but for the RegExp, if you modify this list, you must put the flag `/gmi` at the end of the RegExp (ex: `/(X-Amz-Cf-)(.*)/gim`) * * @defaultValue To get the full list, see {@link DEFAULT_LAMBDA_EDGE_DISALLOWED_HEADERS}. */ disallowedHeaders?: (string | RegExp)[]; /** * If you want to change how we check against the header if it should be stripped, you can pass a function to this property. * * @param header - The header of the response * @defaultValue The default method is implemented to test the header against the list {@link RequestLambdaEdgeAdapterOptions.disallowedHeaders}. */ shouldStripHeader?: (header: string) => boolean; } /** * The adapter to handle requests from AWS Lambda\@Edge of the type Viewer Request. * * The idea of this Adapter is to you be able to expose your framework to the Edge, like when you build for Cloudfront. * * {@link https://docs.aws.amazon.com/lambda/latest/dg/lambda-edge.html | Lambda edge docs} * {@link https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-event-structure.html | Event Reference} * * @example * ```typescript * const stripBasePath = '/api'; // in case you have configure the cloudfront to forward the path /api to your lambda * const adapter = new RequestLambdaEdgeAdapter({ stripBasePath }); * ``` * * @breadcrumb Adapters / AWS / RequestLambdaEdgeAdapter * @public */ declare class RequestLambdaEdgeAdapter implements AdapterContract<CloudFrontRequestEvent, Context, CloudFrontResultResponse> { protected readonly options?: RequestLambdaEdgeAdapterOptions | undefined; /** * Default constructor * * @param options - The options to customize the {@link RequestLambdaEdgeAdapter} */ constructor(options?: RequestLambdaEdgeAdapterOptions | undefined); /** * Strip base path function */ protected readonly stripPathFn: StripBasePathFn; /** * This property is used to cache the disallowed headers in `RegExp` version, even if you provide a string in `disallowedHeader`, we will cache it in an instance of `RegExp`. */ protected readonly cachedDisallowedHeaders: RegExp[]; /** * {@inheritDoc} */ getAdapterName(): string; /** * {@inheritDoc} */ canHandle(event: unknown): event is CloudFrontRequestEvent; /** * {@inheritDoc} */ getRequest(event: CloudFrontRequestEvent): AdapterRequest; /** * {@inheritDoc} */ getResponse({ body, headers: frameworkHeaders, isBase64Encoded, statusCode, log, event, }: GetResponseAdapterProps<CloudFrontRequestEvent>): CloudFrontResultResponse; /** * {@inheritDoc} */ onErrorWhileForwarding({ error, delegatedResolver, respondWithErrors, log, event, }: OnErrorProps<CloudFrontRequestEvent, CloudFrontRequestResult>): void; /** * Returns the headers with the flattened (non-list) values of the cloudfront request headers * * @param cloudFrontRequest - The cloudfront request */ protected getFlattenedHeadersFromCloudfrontRequest(cloudFrontRequest: CloudFrontRequest): SingleValueHeaders; /** * Returns headers in Cloudfront Response format. * * @param originalHeaders - The original version of the request sent by the framework */ protected getHeadersForCloudfrontResponse(originalHeaders: BothValueHeaders): CloudFrontHeaders; /** * Returns the information if we should remove the response header * * @param headerKey - The header that will be tested */ protected shouldStripHeader(headerKey: string): boolean; } export { type AWSSimpleAdapterOptions, type AWSSimpleAdapterResponseType, AlbAdapter, type AlbAdapterOptions, ApiGatewayV1Adapter, type ApiGatewayV1Options, ApiGatewayV2Adapter, type ApiGatewayV2Options, AwsSimpleAdapter, type BatchItemFailureResponse, DEFAULT_LAMBDA_EDGE_DISALLOWED_HEADERS, DEFAULT_ORIGIN_MAX_RESPONSE_SIZE_IN_BYTES, DEFAULT_VIEWER_MAX_RESPONSE_SIZE_IN_BYTES, type DefaultForwardPath, type DefaultQueryString, DynamoDBAdapter, type DynamoDBAdapterOptions, EventBridgeAdapter, type EventBridgeEventAll, type EventBridgeOptions, LambdaEdgeAdapter, type LambdaEdgeAdapterOptions, type NewLambdaEdgeBody, type OldLambdaEdgeBody, RequestLambdaEdgeAdapter, type RequestLambdaEdgeAdapterOptions, S3Adapter, type S3AdapterOptions, SNSAdapter, type SNSAdapterOptions, SQSAdapter, type SQSAdapterOptions };