@bitblit/epsilon
Version:
Tiny adapter to simplify building API gateway Lambda APIS
78 lines • 2.78 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AwsUtil = void 0;
// This class holds any random stuff I need to deal with AWS weirdness
class AwsUtil {
static apiGatewayV2ToApiGatewayV1(srcEvt) {
const rval = {
requestContext: AwsUtil.apiGatewayV2RequestContextToApiGatewayV1RequestContext(srcEvt.requestContext),
httpMethod: srcEvt.requestContext.http.method,
path: srcEvt.requestContext.http.path,
queryStringParameters: srcEvt.queryStringParameters,
headers: srcEvt.headers,
body: srcEvt.body,
isBase64Encoded: srcEvt.isBase64Encoded,
multiValueHeaders: null,
multiValueQueryStringParameters: null,
pathParameters: srcEvt.pathParameters,
stageVariables: srcEvt.stageVariables,
resource: null,
};
return rval;
}
static apiGatewayV2RequestContextToApiGatewayV1RequestContext(srcEvt) {
const rval = {
accountId: srcEvt.accountId,
apiId: srcEvt.apiId,
authorizer: null,
domainName: srcEvt.domainName,
domainPrefix: srcEvt.domainPrefix,
requestId: srcEvt.requestId,
routeKey: srcEvt.routeKey,
stage: srcEvt.stage,
requestTime: srcEvt.time,
requestTimeEpoch: srcEvt.timeEpoch,
//connectedAt?: number | undefined;
//connectionId?: string | undefined;
//eventType?: string | undefined;
//extendedRequestId?: string | undefined;
protocol: srcEvt.http.protocol,
httpMethod: srcEvt.http.method,
identity: null,
//messageDirection?: string | undefined;
//messageId?: string | null | undefined;
path: srcEvt.http.path,
resourceId: null,
resourcePath: null, //string;
};
return rval;
}
static findInMap(toFind, map) {
let rval = null;
map.forEach((val, key) => {
if (AwsUtil.matchExact(key, toFind)) {
rval = val;
}
});
return rval;
}
static matchExact(r, str) {
const match = str.match(r);
return match != null && str == match[0];
}
// Returns either the value if non-function, the result if function, and default if neither
static resolvePotentialFunctionToResult(src, def) {
let rval = def;
if (src) {
if (typeof src === 'function') {
rval = src();
}
else {
rval = src;
}
}
return rval;
}
}
exports.AwsUtil = AwsUtil;
//# sourceMappingURL=aws-util.js.map