npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@x82-softworks/aws-api

v1.0.2

Published

An OpenAPI compatible api system intended for use with AWS Lambda and API Gateway

Downloads

32

Readme

@x82-softworks/aws-api

An OpenAPI compatible API builder for AWS API Gateway and Lambda

This project is intended to create a proxy lambda setup with API Gateway. It smooths over many problems with standard express hosting as it is tailored to the AWS lambda environment.

Auto generated docs

https://x82-open-source.gitlab.io/npm/aws-api

Example usage

// src/index.js
import spec from "./spec"

export const handler = spec.lambda()
// src/spec.js
import { STRING, create } from "@x82-softworks/aws-api"
import routes from "./routes"
import selfPkg from "../package.json"

const CORS_WHITELIST = (process.env.CORS_WHITELIST || "").split(",")
const SUPPORT_EMAIL = process.env.SUPPORT_EMAIL
const HOST = process.env.HOST
const VERSION = process.env.VERSION

const spec = create({
  info: {
    version: VERSION,
    description: selfPkg.description,
    title: HOST,
    contact: {
      name: "API Support",
      email: SUPPORT_EMAIL,
    },
  },
  host: HOST,
  basePath: VERSION ? "/" + VERSION + "/" : "/",
  security: [
    {
      apiKey: [],
    },
  ],
})
//Set the default cors
spec.cors((req, res) => {
  try {
    let origin = new URL(req.headers.origin).hostname
    if (CORS_WHITELIST.indexOf(origin) !== -1) {
      res.headers["Access-Control-Allow-Origin"] = req.headers.origin
    }
  } catch (err) {
    //ignore
  }

  res.headers["Access-Control-Allow-Methods"] =
    "GET,OPTIONS,HEAD,PUT,PATCH,DELETE,POST"
  res.headers["Access-Control-Allow-headers"] =
    "Content-Type,authorization,x-date"
})
//Now load the schemas
routes(spec)
export default spec
// src/routes
import example from "./example"
import openapi from "./openapi"
export default (spec, services) => {
  ;[example, openapi].forEach(routeController =>
    routeController(spec, services)
  )
}
// src/openapi
export default spec => {
  spec.get(
    "/openapi.json",
    {
      description: "Retrieves the OpenApi spec doc",
      responses: {
        200: {
          description,
          content: {
            "application/json": {
              schema: {},
            },
          },
        },
      },
      //No security needed
      security: [],
    },
    async (req, res) => {
      res.body = spec.getRoot()
    }
  )
}
import { ARRAY, BOOLEAN, INTEGER, NUMBER, OBJECT, STRING } from '@x82-softworks/aws-api';
// src/example
export default spec => {
  spec.post(
    '/example/endpoint',
    {
      description: 'Retrieves the OpenApi spec doc',
      requestBody: {
            description:'The json input',
            content: {
            'application/json': {
                schema: {
                    properties:{
                            fizz: {
                                    type: STRING,
                                    description: 'Your fizz value'
                                },
                                bang: {
                                    type: NUMBER,
                                    description: 'Your bang amount'
                                }
                    },
                    additionalProperties: false,
                    required: required: ['fizz','bang']
                    }
                }
            }
        },
        responses:{
            200: {
            description,
            content: {
            'application/json': {
                    schema:{
                    description: 'The result',
                    type: OBJECT,
                    properties: {
                        fizz: {
                                type: STRING,
                                description: 'Your fizz value'
                            },
                            bang: {
                                type: NUMBER,
                                description: 'Your bang amount'
                            }
                    }
                }
            }
        }
      },
      //No security needed
      security: []
    },
    async (req, res) => {
      res.body = {
          fizz :req.body.fizz,
          bang: req.body.bang
      };
    }
  );
};