Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
@qrvey/function-gateway
Advanced tools
![install size](https://packagephobia.com/badge?p=%40qrvey%2Ffunction-gateway) ![coverage](https://img.shields.io/badge/unit_test_coverage-100%25-brightgreen)
The @qrvey/function-gateway
package provides a unified interface for invoking lambda and REST functions based on the specific configurations of the service.
You can install the package using npm or yarn:
npm install @qrvey/function-gateway
Or with yarn:
yarn add @qrvey/function-gateway
Note: If the application does not have @aws-sdk/client-lambda installed, it must be installed manually. @qrvey/function-gateway requires it to make Lambda invoke calls.
The function gateway in the @qrvey/function-gateway
package can invoke functions either as a Lambda function or as a REST API call, depending on certain conditions. These conditions are determined by:
REST Invocation:
PLATFORM_TYPE
is set to 'CONTAINER'
and the function mapping contains a REST configuration.options.mappingType
parameter is explicitly set to 'rest'
.Lambda Invocation:
options.mappingType
parameter is explicitly set to 'lambda'
.options.mappingType
being specified, the function gateway will default to Lambda invocation unless there is a REST configuration and no Lambda configuration.const { FunctionGatewayService } = require("@qrvey/function-gateway");
const mapper = require("./fnGwMapping");
class MyFunctionGateway extends FunctionGatewayService {
getInfoById(id) {
const headers: {
'x-api-key': 'my-api-key'
}
const params = { headers, dataId: id };
return MyFunctionGateway.invoke("getData", params, mapper);
}
}
const myFunctionGw = new MyFunctionGateway();
myFunctionGw
.getInfoById("my_id")
.then((res) => {
// Handle successful result
console.log(JSON.parse(res.Payload));
})
.catch((error) => {
// Handle errors
console.log(error);
});
FunctionGatewayService
static invoke(functionName: string, params: unknown, functionMapping: IFunctionMapping, options: IFunctionOptions): Promise<any>
functionName
: The name of the function to invoke.params
: Parameters to be provided to the corresponding property in the functionMapping definition.functionMapping
: An object that maps function names to function implementations.options
: An object containing additional options for invoking the function.functionMapping param
Defines the mapping of function names to their corresponding implementations.
Example
This example demonstrates how to configure both a Lambda function and a REST API call:
const mapper = {
// Define a mapping for a function named 'getData'
getData: (param) => {
return {
// Configuration for a Lambda invocation
lambda: {
// [required] The name of the Lambda function
name: process.env.SERVER_PREFIX + '_getDataFunction',
// [required] The payload to send to the Lambda function
payload: {
headers: param.headers,
method: 'get', // HTTP method for the request
body: {
pathParameters: {
dataID: param.dataID, // Parameters to pass to the Lambda function
},
},
},
// [optional]
options: {
asHttp: false,
//invocationParams defines the additional params to be passed in lambda.invoke call
invocationParams: {
Qualifier: 'my_lambda_alias' //should be the name of the property used in lambda.invoke of @aws-sdk/client-lambda library
},
},
// A callback function to handle the Lambda response
callback: (res) => {
const responseObj = JSON.parse(res.Payload);
return responseObj.data; // Extracting and returning the data from the response
},
},
// Configuration for REST API invocation
rest: {
// The URL for the REST API call
endpoint: `/api/service-data/${param.dataID}`,
// The HTTP method for the request
method: 'get',
// Additional options for the REST API call
options: {
baseDomain: process.env.API_DOMAIN,
headers: param.headers, // Headers to include in the request
},
},
};
}
};
FAQs
![install size](https://packagephobia.com/badge?p=%40qrvey%2Ffunction-gateway) ![coverage](https://img.shields.io/badge/unit_test_coverage-100%25-brightgreen)
The npm package @qrvey/function-gateway receives a total of 810 weekly downloads. As such, @qrvey/function-gateway popularity was classified as not popular.
We found that @qrvey/function-gateway demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.