@bitblit/epsilon
Version:
Tiny adapter to simplify building API gateway Lambda APIS
40 lines • 1.94 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.WebV2Handler = void 0;
const aws_util_1 = require("../util/aws-util");
const aws_1 = require("@bitblit/ratchet/aws");
/**
* This class functions as the adapter from a default lambda function to the handlers exposed via Epsilon
*/
class WebV2Handler {
constructor(webHandler) {
this.webHandler = webHandler;
}
extractLabel(evt, context) {
let rval = this.webHandler.extractLabel(aws_util_1.AwsUtil.apiGatewayV2ToApiGatewayV1(evt), context);
rval = rval.replace('WEB:', 'WEB2:');
return rval;
}
handlesEvent(evt) {
return aws_1.LambdaEventDetector.isValidApiGatewayV2WithRequestContextEvent(evt);
}
processEvent(evt, context) {
return __awaiter(this, void 0, void 0, function* () {
const conv = aws_util_1.AwsUtil.apiGatewayV2ToApiGatewayV1(evt);
const asExtended = Object.assign({}, { parsedBody: null, authorization: null, convertedFromV2Event: true }, conv);
const rval = yield this.webHandler.openApiLambdaHandler(asExtended, context);
return rval;
});
}
}
exports.WebV2Handler = WebV2Handler;
//# sourceMappingURL=web-v2-handler.js.map