Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
};
const validateEnabledFlag = enabled => {
if (!enabled) {
throw new Error("Place order lambda is off");
}
};
const instances = ({ env }) => ({
orderRepository: new DynamoDbOrderRepository(env.ORDER_TABLE_NAME),
idGenerator: new UuidIdGenerator(),
orderStream: new KinesisOrderStream(env.ORDER_STREAM_NAME)
});
const apigateway = adapterApi.apigateway({
inputType: "body",
includeInputHeaders: true,
errorMappings: {
ValidationError: () => ({ statusCode: 400 })
}
});
exports.app = async (
newOrder,
headers,
{ orderRepository, orderStream, idGenerator, apiKey, restaurants, enabled }
) => {
validateEnabledFlag(enabled);
validateApiKey(headers, apiKey);
const orderId = idGenerator.generate();
const order = Object.assign(
const fs = require("fs");
const laconia = require("@laconia/core");
const adapterApi = require("@laconia/adapter-api");
const apigateway = adapterApi.apigateway({
responseAdditionalHeaders: {
"Content-Type": "image/png"
}
});
const imgPath = `${__dirname}/resources/2_vertical@0.5x.png`;
exports.app = () => fs.readFileSync(imgPath);
exports.handler = laconia(apigateway(exports.app));
const WebSocketClient = require("./WebSocketClient");
const instances = ({ event, env }) => ({
wsClient: new WebSocketClient(
env.WEBSOCKET_ENDPOINT,
event.requestContext.connectionId
)
});
const app = async (message, { wsClient }) => {
if (message.body.message === "order received") {
return wsClient.send({ message: "thank you for your order" });
}
};
const webSocket = adapterApi.webSocket();
exports.handler = laconia(webSocket(app)).register(instances, {
cache: { enabled: false }
});