How to use @laconia/adapter-api - 3 common examples

To help you get started, we’ve selected a few @laconia/adapter-api examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github laconiajs / laconia / packages / laconia-acceptance-test / src / place-order.js View on Github external
}
};

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(
github laconiajs / laconia / packages / laconia-acceptance-test / src / download-image.js View on Github external
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));
github laconiajs / laconia / packages / laconia-acceptance-test / src / update-user-receipt.js View on Github external
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 }
});

@laconia/adapter-api

Converts API Gateway Proxy events into your application input

Apache-2.0
Latest version published 2 years ago

Package Health Score

62 / 100
Full package analysis