Skip to main content

Introduction

@h4ad/serverless-adapter

(package) serverless-adapter

Classes

ClassDescription
AlbAdapterThe adapter to handle requests from AWS ALB
ApiGatewayV1Adapter

The adapter to handle requests from AWS Api Gateway V1

As per know issues , we throw an exception when you send the transfer-encoding=chunked, currently, API Gateway doesn't support chunked transfer.

ApiGatewayV2Adapter

The adapter to handle requests from AWS Api Gateway V2

As per 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.

ApolloServerFrameworkThe framework that forwards requests to Apollo Server
ApolloServerMutationAdapterThe adapter that wraps another adapter to force a transformation of the event data as a mutation to Apollo Server be able to handle.
AwsContextResolverThe class that implements the resolver by using the AWS Context object.
AwsSimpleAdapterThe abstract adapter to use to implement other simple AWS adapters
AwsStreamHandlerThe class that implements a default serverless handler consisting of a function with event, context and callback parameters respectively
AzureHandler

The class that implements a serverless handler for Azure Function.

When you don't specify a custom logger, the logger is used instead.

BaseBodyParserFrameworkThe base class used by other body-parser functions to parse a specific content-type
BaseHandlerThe abstract class that represents the base class for a handler
BufferToJSObjectTransformerThe transformer that is responsible to transform buffer's input to javascript objects
CallbackResolverThe class that implements the resolver using the callback function sent by serverless
CorsFrameworkThe framework that handles cors for your api without relying on internals of the framework
DefaultHandlerThe class that implements a default serverless handler consisting of a function with event, context and callback parameters respectively
DigitalOceanHandlerThe class that implements a serverless handler for Digital Ocean Functions.
DummyAdapterThe class that represents a dummy adapter that does nothing and can be used by the cloud that doesn't use adapters.
DummyResolverThe class that represents a dummy resolver that does nothing and can be used by the cloud that doesn't use resolvers.
DynamoDBAdapter

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.

Event Reference

EventBridgeAdapter

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.

Event Reference

ExpressFrameworkThe framework that forwards requests to express handler
FastifyFrameworkThe framework that forwards requests to fastify handler
GCPHandlerThe class that implements a handler for GCP Http Functions
HapiFrameworkThe framework that forwards requests to hapi handler
HttpDeepkitFrameworkThe framework that forwards requests to express handler
HttpFirebaseHandlerThe class that implements a handler for Firebase Https Events
HttpFirebaseV2HandlerThe class that implements a handler for Firebase Https Events
HttpFunctionAdapterThe adapter to handle requests from Digital Ocean Functions when called from HTTP Endpoint.
HttpHuaweiHandler

The class that implements a huawei serverless handler with http function that exposes a http server in specific port.

In this Handler, you don't need to specific resolver and adapter, so you can use DummyAdapter and DummyResolver instead.

HttpTriggerV4AdapterThe adapter to handle requests from Http Trigger on Azure Function V4.
HuaweiApiGatewayAdapterThe adapter to handle requests from Huawei Api Gateway
JsonBodyParserFrameworkThe body-parser class used to parse application/json.
KoaFrameworkThe framework that forwards requests to koa handler
LambdaEdgeAdapter

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 NewLambdaEdgeBody instead 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 . 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.

Lambda edge docs Event Reference

LazyFrameworkThe framework that asynchronously instantiates your application and forwards the request to the framework as quickly as possible.
PolkaFrameworkThe framework that forwards requests to polka handler
PromiseResolverThe class that implements the resolver using the promise object sent by this library
RawBodyParserFrameworkThe body-parser class used to parse application/octet-stream.
RawRequestThe class that expose some methods to be used to get raw request from Express HTTP Request
RequestLambdaEdgeAdapter

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.

Lambda edge docs Event Reference

S3Adapter

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.

Event Reference

ServerlessAdapterThe class used to build the serverless handler.
ServerlessRequestThe class that represents an created by the library to represent an actual request to the framework.
ServerlessResponseThe class that represents a response instance used to send to the framework and wait until the framework finishes processing the request. Once it's happens, we use the properties from this response to built the response to the cloud.
ServerlessStreamResponseThe class that represents a response instance used to send to the framework and wait until the framework finishes processing the request. This response is specially built to deal with transfer-encoding: chunked
SNSAdapter

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.

Event Reference

SQSAdapter

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.

Event Reference

TextBodyParserFrameworkThe body-parser class used to parse text/plain.
TrpcFrameworkThe framework that forwards requests to TRPC handler
UrlencodedBodyParserFrameworkThe body-parser class used to parse application/x-www-form-urlencoded.

Functions

FunctionDescription
buildStripBasePath(basePath)Get the strip base path function
createDefaultLogger({ level })The method used to create a simple logger instance to use in this library.
getContentType(headers)The function that returns the content type of headers
getCurrentInvoke()Get the reference to the event created by the serverless trigger or context created by the serverless environment.
getDefaultIfUndefined(value, defaultValue)Return the defaultValue whether the value is undefined, otherwise, return the value.
getEventBodyAsBuffer(body, isBase64Encoded)Get the event body as buffer from body string with content length
getFlattenedHeadersMap(headersMap, separator, lowerCaseKey)Transform a header map and make sure the value is not an array
getFlattenedHeadersMapAndCookies(headersMap)Transforms a header map into a single value headers and cookies
getMultiValueHeadersMap(headersMap)Transforms a header map into a multi-value map header.
getPathWithQueryStringParams(path, queryParams)Transform the path and a map of query params to a string with formatted query params
getQueryParamsStringFromRecord(queryParamsRecord)Map query params to a string with formatted query params
getString(data)Get the data from a buffer, string, or Uint8Array
isBinary(headers, binarySettings)The function used to determine from the headers and the binary settings if a response should be encoded or not
isContentEncodingBinary(headers, binaryEncodingTypes)The function that determines by the content encoding whether the response should be treated as binary
isContentTypeBinary(headers, binaryContentTypes)The function that determines by the content type whether the response should be treated as binary
isInternalLogger(logger)The method used to chck if logger was created by this library, or it was defined by the user.
isStreamEnded(stream)Check if stream already ended
parseHeaders(headers)Parse HTTP Raw Headers Attribution to https://github.com/kesla/parse-headers/blob/master/parse-headers.js
setCurrentInvoke({ event, context, })Method that saves to the event created by the serverless trigger or context created by the serverless environment.
waitForStreamComplete(stream)Wait asynchronous the stream to complete

Interfaces

InterfaceDescription
AdapterContractThe interface that represents a contract between the adapter and the actual implementation of the adapter.
AdapterRequestThe request interface used to bridge any event source to the framework.
AlbAdapterOptionsThe options to customize the AlbAdapter
ApiGatewayV1OptionsThe options to customize the ApiGatewayV1Adapter
ApiGatewayV2OptionsThe options to customize the ApiGatewayV2Adapter
ApolloServerOptionsThe options to customize ApolloServerFramework
AWSSimpleAdapterOptionsThe options to customize the AwsSimpleAdapter
AzureHandlerOptionsThe options to customize AzureHandler
BinarySettingsContentHeadersThe interface representing the binary settings implementation by looking inside the headers
BinarySettingsFunctionThe interface representing the binary settings implementation by function
DefaultServerlessApolloServerContextThe default context of Apollo Server when you integrate and don't pass any context.
DynamoDBAdapterOptionsThe options to customize the DynamoDBAdapter
EventBridgeOptionsThe options to customize the EventBridgeAdapter
FrameworkContractThe interface that represents a contract between the framework and the framework implementation
GetResponseAdapterPropsThe props of the method that get the response from the framework and transform it into a format that the event source can handle
HandlerContractThe interface that represents the contract between the handler and the real implementation
HttpFunctionAdapterOptionsThe options to customize the HttpFunctionAdapter
HttpTriggerV4AdapterOptionsThe options to customize the HttpTriggerV4Adapter
HuaweiApiGatewayEventThe interface that represents the Api Gateway Event of Huawei when integrate with Function Graph of Event Type. See more in Reference .
HuaweiApiGatewayOptionsThe options to customize the HuaweiApiGatewayAdapter
HuaweiApiGatewayResponseThe interface that represents the Api Gateway Response of Huawei when integrate with Function Graph of Event Type. See more in Reference .
HuaweiContextThe interface that represents methods sent by huawei to get information about the function graph. See more in Context Methods
HuaweiRequestContextThe interface that represents the values you can get inside request context.
LambdaEdgeAdapterOptionsThe options to customize the LambdaEdgeAdapter .
OnErrorPropsThe props of the method that handle the response when an error occurs while forwarding the request to the framework
RequestLambdaEdgeAdapterOptionsThe options to customize the RequestLambdaEdgeAdapter .
ResolverContractThe interface that represents the contract used to send the response to the client
S3AdapterOptionsThe options to customize the S3Adapter
ServerlessRequestPropsThe properties to create a ServerlessRequest
ServerlessResponsePropsThe properties to create a ServerlessResponse .
ServerlessStreamResponsePropsThe properties to create a ServerlessStreamResponse .
SNSAdapterOptionsThe options to customize the SNSAdapter
SQSAdapterOptionsThe options to customize the SQSAdapter
TrpcAdapterBaseContextThe context created by this library that allows getting some information from the request and setting the status and header of the response.

Variables

VariableDescription
DEFAULT_BINARY_CONTENT_TYPESDefault content types that are treated as binary, they are compared with the Content-Type header.
DEFAULT_BINARY_ENCODINGSDefault encodings that are treated as binary, they are compared with the Content-Encoding header.
DEFAULT_HUAWEI_LISTEN_PORT

The default port that huawei will proxy the request to your framework

Reference

DEFAULT_LAMBDA_EDGE_DISALLOWED_HEADERSThe list was created based on these docs in the "Disallowed Headers" section.
DEFAULT_ORIGIN_MAX_RESPONSE_SIZE_IN_BYTESThe default max response size in bytes of origin request and origin response.
DEFAULT_VIEWER_MAX_RESPONSE_SIZE_IN_BYTESThe default max response size in bytes of viewer request and viewer response.
EmptyResponseConstant for empty response and can be used on some adapters when the adapter does not need to return a response.
NO_OPNo operation function is used when we need to pass a function, but we don't want to specify any behavior.

Type Aliases

Type AliasDescription
ApolloServerContextArgumentsThe arguments used to create a Context inside ApolloServerOptions
ApolloServerMutationAdapterOptionsThe options for ApolloServerMutationAdapter
AWSResponseStream
AWSSimpleAdapterResponseTypeThe possible options of response for AwsSimpleAdapter
AWSStreamContextThe interface that describes the internal context used by the AwsStreamHandler
AWSStreamResponseMetadata
BatchItemFailureResponseThe batch item failure response expected from the API server
BinarySettingsThe interface representing the settings for whether the response should be treated as binary or not
BodyParserOptionsThe options for BaseBodyParserFramework
BothValueHeadersThe record that represents the headers that can both single or multiple values in the value
ConcreteRemoves 'optional' attributes from a type's properties
CorsFrameworkOptionsThe options to customize CorsFramework
CurrentInvokeThe type that represents the object that handles the references to the event created by the serverless trigger or context created by the serverless environment.
DefaultForwardPathThe type alias to indicate where we get the default value of path to create the request.
DefaultQueryStringThe type alias to indicate where we get the default value of query string to create the request.
DelegatedResolverThe type that represents a delegate resolver that is passed to the adapter to handle what to do when an error occurs during forwarding.
EventBridgeEventAllJust a type alias to ignore generic types in the event
FirebaseHttpHandlerThe HTTP handler that is exposed when you use HttpFirebaseV2Handler .
FlattenedHeadersAndCookiesThe wrapper that holds the information about single value headers and cookies
GetAccessKeyReturnThe return value of HuaweiContext getAccessKey
GetCPUNumberReturnThe return value of HuaweiContext getCPUNumber
GetFunctionNameReturnThe return value of HuaweiContext getFunctionName
GetLoggerReturn

The return value of HuaweiContext getLogger

Is the instance of logger that can be used to send logs to

GetMemorySizeReturnThe return value of HuaweiContext getMemorySize
GetPackageReturnThe return value of HuaweiContext getPackage
GetProjectIdReturnThe return value of HuaweiContext getProjectID
GetRemainingTimeInMilliSecondsReturnThe return value of HuaweiContext getRemainingTimeInMilliSeconds
GetRequestIDSecondsReturnThe return value of HuaweiContext getRequestID
GetRunningTimeInSecondsReturnThe return value of HuaweiContext getRunningTimeInSeconds
GetSecretKeyReturnThe return value of HuaweiContext getSecretKey
GetTokenReturnThe return value of HuaweiContext getToken
GetUserDataKeyParameterThe parameters of the method HuaweiContext getUserData
GetUserDataReturnThe return value of HuaweiContext getUserData
GetVersionReturnThe return value of HuaweiContext getVersion
HttpHuaweiHandlerOptionsThe options to customize HttpHuaweiHandler
HuaweiRequestPathParametersThe path parameters of the request, usually is the name of the wildcard you create in FunctionGraph, such as / { proxy } .
HuaweiRequestQueryStringParametersThe query strings of the request
IEmptyResponseType alias for empty response and can be used on some adapters when the adapter does not need to return a response.
ILoggerThe interface representing the logger, you can provide a custom logger by implementing this interface.
JsonBodyParserFrameworkOptionsThe body-parser options for application/json
LoggerFNThe log function used in any level.
LoggerOptionsThe options to customize ILogger
LogLevelsThe type representing the possible log levels to choose from.
MultiValueHeadersThe record that represents the headers that have multiple values in the value
NewLambdaEdgeBodyRepresents the body of the new version of Lambda @ edge, which uses the body property inside request as the body (library) of the request.
OldLambdaEdgeBodyRepresents 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.
RawBodyParserFrameworkOptionsThe body-parser options for application/octet-stream
ResolverThe type that represents a resolver used to send the response, error or success, to the client
ResolverPropsThe createResolver contract props
ServerlessCallbackThe default signature of the callback sent by serverless
ServerlessHandlerThe function used to handle serverless requests
SingleValueHeadersThe record that represents the headers that doesn't have multiple values in the value
StripBasePathFnType of the function to strip base path
TextBodyParserFrameworkOptionsThe body-parser options for text/plain
TrpcAdapterContext

This is the context merged between TrpcAdapterBaseContext and the that you provided.

This context will be merged with the context you created with createContext inside TrpcFrameworkOptions . So to make the type work, just send the properties you've added inside .

TrpcFrameworkOptionsThe options to customize the TrpcFramework
UrlencodedBodyParserFrameworkOptionsThe body parser options for application/x-www-form-urlencoded