@aesop-fables/triginta
Advanced tools
Comparing version 0.2.4 to 0.3.0
import { IServiceContainer, IServiceModule, Newable } from '@aesop-fables/containr'; | ||
import { APIGatewayProxyEventV2, Handler } from 'aws-lambda'; | ||
import { APIGatewayProxyEventV2, APIGatewayProxyStructuredResultV2, Handler } from 'aws-lambda'; | ||
import { IHttpEndpoint } from './IHttpEndpoint'; | ||
export declare type NonNoisyEvent = Omit<APIGatewayProxyEventV2, 'requestContext'>; | ||
export interface BootstrappedHttpLambdaContext { | ||
createHttpLambda<Input, Output>(newable: Newable<IHttpEndpoint<Input, Output>>): Handler<APIGatewayProxyEventV2, Output>; | ||
createHttpLambda<Input, Output>(newable: Newable<IHttpEndpoint<Input, Output>>): Handler<APIGatewayProxyEventV2, APIGatewayProxyStructuredResultV2>; | ||
} | ||
export interface IHttpLambdaFactory { | ||
createHandler<Input, Output>(newable: Newable<IHttpEndpoint<Input, Output>>): Handler<APIGatewayProxyEventV2, Output>; | ||
createHandler<Input, Output>(newable: Newable<IHttpEndpoint<Input, Output>>): Handler<APIGatewayProxyEventV2, APIGatewayProxyStructuredResultV2>; | ||
} | ||
@@ -14,3 +14,3 @@ export declare class HttpLambdaFactory implements IHttpLambdaFactory { | ||
constructor(container: IServiceContainer); | ||
createHandler<Input, Output>(newable: Newable<IHttpEndpoint<Input, Output>>): Handler<APIGatewayProxyEventV2, Output>; | ||
createHandler<Input, Output>(newable: Newable<IHttpEndpoint<Input, Output>>): Handler<APIGatewayProxyEventV2, APIGatewayProxyStructuredResultV2>; | ||
} | ||
@@ -17,0 +17,0 @@ export declare const useTrigintaHttp: IServiceModule; |
@@ -34,3 +34,12 @@ "use strict"; | ||
const response = (yield endpoint.handle(request, event)); | ||
return response; | ||
// TODO -- Break this out into a response writer | ||
let proxyResponse = response; | ||
if (typeof (proxyResponse === null || proxyResponse === void 0 ? void 0 : proxyResponse.statusCode) === 'undefined') { | ||
// TODO -- Is 200 always correct here? | ||
proxyResponse = { | ||
statusCode: 200, | ||
body: response ? JSON.stringify(response) : undefined, | ||
}; | ||
} | ||
return proxyResponse; | ||
} | ||
@@ -37,0 +46,0 @@ finally { |
@@ -9,2 +9,3 @@ import { IHandler } from './IHandler'; | ||
export * from './invokeHttpHandler'; | ||
export * from './IConfiguredRoute'; | ||
export { IHandler, IHttpEndpoint }; |
@@ -28,1 +28,2 @@ "use strict"; | ||
__exportStar(require("./invokeHttpHandler"), exports); | ||
__exportStar(require("./IConfiguredRoute"), exports); |
@@ -1,2 +0,2 @@ | ||
import { APIGatewayProxyEventPathParameters, APIGatewayProxyEventV2 } from 'aws-lambda'; | ||
import { APIGatewayProxyEventPathParameters, APIGatewayProxyEventV2, APIGatewayProxyStructuredResultV2 } from 'aws-lambda'; | ||
import { IServiceContainer } from '@aesop-fables/containr'; | ||
@@ -14,2 +14,2 @@ import { IConfiguredRoute } from './IConfiguredRoute'; | ||
export declare function createApiGatewayEvent(context: EventGenerationContext): Partial<APIGatewayProxyEventV2>; | ||
export declare function invokeHttpHandler<Output>(context: InvocationContext): Promise<Output>; | ||
export declare function invokeHttpHandler<Output>(context: InvocationContext): Promise<APIGatewayProxyStructuredResultV2>; |
@@ -80,3 +80,3 @@ "use strict"; | ||
// 'content-length': '0', | ||
// 'content-type': 'application/json', | ||
'content-type': 'application/json', | ||
host: '', | ||
@@ -118,3 +118,4 @@ 'user-agent': 'triginta/1.0', | ||
const configuredHandler = factory.createHandler(context.configuredRoute.constructor); | ||
return configuredHandler(createApiGatewayEvent(context), { | ||
const event = createApiGatewayEvent(context); | ||
const handlerContext = { | ||
callbackWaitsForEmptyEventLoop: false, | ||
@@ -129,3 +130,3 @@ functionName: 'httpLambda', | ||
getRemainingTimeInMillis: function () { | ||
throw new Error('Function not implemented.'); | ||
return 1000; | ||
}, | ||
@@ -141,8 +142,7 @@ done: function (error, result) { | ||
}, | ||
}, () => { | ||
// no-op | ||
throw new Error('Not supported'); | ||
}); | ||
}; | ||
const response = yield configuredHandler(event, handlerContext); | ||
return response; | ||
}); | ||
} | ||
exports.invokeHttpHandler = invokeHttpHandler; |
@@ -1,10 +0,1 @@ | ||
import middy from '@middy/core'; | ||
export declare const errorWrapper: () => { | ||
onError: (handler: middy.HandlerLambda, next: middy.NextFunction) => void; | ||
}; | ||
export declare const convertNullTo200: () => { | ||
after: (handler: middy.HandlerLambda, next: middy.NextFunction) => void; | ||
}; | ||
export declare const xssFilter: () => { | ||
before: (handler: middy.HandlerLambda) => Promise<void>; | ||
}; | ||
export {}; |
"use strict"; | ||
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()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.xssFilter = exports.convertNullTo200 = exports.errorWrapper = void 0; | ||
const xss_1 = __importDefault(require("xss")); | ||
const errorWrapper = () => ({ | ||
onError: (handler, next) => { | ||
if (handler.error) { | ||
handler.response = { | ||
statusCode: 400, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Access-Control-Allow-Origin': '*', | ||
'Access-Control-Allow-Headers': '*', | ||
'Access-Control-Allow-Methods': '*', | ||
}, | ||
body: JSON.stringify({ | ||
error: handler.error, | ||
}), | ||
}; | ||
return next(); | ||
} | ||
return next(handler.error); | ||
}, | ||
}); | ||
exports.errorWrapper = errorWrapper; | ||
const convertNullTo200 = () => ({ | ||
after: (handler, next) => { | ||
if (handler.response === null) { | ||
handler.response = { | ||
statusCode: 200, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Access-Control-Allow-Origin': '*', | ||
'Access-Control-Allow-Headers': '*', | ||
'Access-Control-Allow-Methods': '*', | ||
}, | ||
body: '', | ||
}; | ||
} | ||
return next(); | ||
}, | ||
}); | ||
exports.convertNullTo200 = convertNullTo200; | ||
const xssFilter = () => ({ | ||
before: (handler) => __awaiter(void 0, void 0, void 0, function* () { | ||
const { event } = handler; | ||
const { body } = event; | ||
if (body) { | ||
const keys = Object.keys(body); | ||
for (let i = 0; i < keys.length; i++) { | ||
const key = keys[i]; | ||
const value = body[key]; | ||
if (value && typeof value === 'string') { | ||
body[key] = (0, xss_1.default)(value); | ||
} | ||
} | ||
} | ||
}), | ||
}); | ||
exports.xssFilter = xssFilter; | ||
// export const errorWrapper = () => ({ | ||
// onError: (handler: middy.MiddyfiedHandler, next: middy.MiddlewareFn) => { | ||
// if (handler.error) { | ||
// handler.response = { | ||
// statusCode: 400, | ||
// headers: { | ||
// 'Content-Type': 'application/json', | ||
// 'Access-Control-Allow-Origin': '*', | ||
// 'Access-Control-Allow-Headers': '*', | ||
// 'Access-Control-Allow-Methods': '*', | ||
// }, | ||
// body: JSON.stringify({ | ||
// error: handler.error, | ||
// }), | ||
// }; | ||
// return next(); | ||
// } | ||
// return next(handler.error); | ||
// }, | ||
// }); | ||
// export const convertNullTo200 = () => ({ | ||
// after: (handler: middy.HandlerLambda, next: middy.NextFunction) => { | ||
// if (handler.response === null) { | ||
// handler.response = { | ||
// statusCode: 200, | ||
// headers: { | ||
// 'Content-Type': 'application/json', | ||
// 'Access-Control-Allow-Origin': '*', | ||
// 'Access-Control-Allow-Headers': '*', | ||
// 'Access-Control-Allow-Methods': '*', | ||
// }, | ||
// body: '', | ||
// }; | ||
// } | ||
// return next(); | ||
// }, | ||
// }); | ||
// export const xssFilter = () => ({ | ||
// before: async (handler: middy.HandlerLambda) => { | ||
// const { event } = handler; | ||
// const { body } = event; | ||
// if (body) { | ||
// const keys = Object.keys(body); | ||
// for (let i = 0; i < keys.length; i++) { | ||
// const key = keys[i]; | ||
// const value = body[key]; | ||
// if (value && typeof value === 'string') { | ||
// body[key] = xss(value); | ||
// } | ||
// } | ||
// } | ||
// }, | ||
// }); |
{ | ||
"name": "@aesop-fables/triginta", | ||
"version": "0.2.4", | ||
"version": "0.3.0", | ||
"description": "A lightweight framework that wraps the basic infrastructure usages of AWS Lambda (SQS, Kinesis, etc.).", | ||
@@ -48,5 +48,5 @@ "type": "commonjs", | ||
"dependencies": { | ||
"@middy/core": "^1.5.2", | ||
"@middy/http-error-handler": "^1.5.2", | ||
"@middy/http-json-body-parser": "^1.5.2", | ||
"@middy/core": "^4.2.3", | ||
"@middy/http-error-handler": "^4.2.3", | ||
"@middy/http-json-body-parser": "^4.2.3", | ||
"reflect-metadata": "^0.1.13", | ||
@@ -53,0 +53,0 @@ "xss": "^1.0.9" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24024
475
+ Added@middy/core@4.7.0(transitive)
+ Added@middy/http-error-handler@4.7.0(transitive)
+ Added@middy/http-json-body-parser@4.7.0(transitive)
+ Added@middy/util@4.7.0(transitive)
- Removed@middy/core@1.5.2(transitive)
- Removed@middy/http-error-handler@1.5.2(transitive)
- Removed@middy/http-json-body-parser@1.5.2(transitive)
- Removed@types/http-errors@1.8.2(transitive)
- Removedcontent-type@1.0.5(transitive)
- Removeddepd@1.1.2(transitive)
- Removedhttp-errors@1.8.1(transitive)
- Removedinherits@2.0.4(transitive)
- Removedonce@1.4.0(transitive)
- Removedsetprototypeof@1.2.0(transitive)
- Removedstatuses@1.5.0(transitive)
- Removedtoidentifier@1.0.1(transitive)
- Removedwrappy@1.0.2(transitive)
Updated@middy/core@^4.2.3