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

@besmarthead/sh-api-framework

v1.0.28

Published

SmartHead framework library for serverless APIs (security, openapi validation, logging ,... )

Downloads

72

Readme

What is SH API Framework

Annotations and libraries (utils) to help solve common tasks with API. Can be used as NPM package or as Lambda layer.

  • validation (with swagger / openapi): annotation '@OpenApi'
  • security (JWT validation): annotation '@SecuredApi'
  • API status handler/logger (ERROR/OK): annotation '@StatusLogger'
  • AWS Logger: util class 'AWSLambdaLogger'

Library as Lambda layer

  • npm run lambda-layer create new lambda layer in AWS.
  • in env/local.yml increase version of lambda layer
  • commit/push (all other packages will after deploy use new lambda version)

QA

  • npm run test to run test
  • npm run coverage to run test with coverage
  • npm run lint to run lint

How to release

Requirement: have user in NPM and be part of team: "developers" in organization "besmarthead" (https://www.npmjs.com/settings/besmarthead/teams/team/developers/users)

  • Check if user is logged into NPM (npm whoami). If user is not logged: npm login
  • lerna publish --no-private

All API projects/packages have in package.json set "private" to true. When publishing with lerna argument "--no-private", those packages are ignored" from publish. Doc: lerna#--no-private

@SecuredApi: Security

Lambda Security implementation (authentication & authorization)

If handler is annotated with @SecuredAPI than API caller must be valid user (e.g. valid token in request):

  • authentication (is token valid / authentic)
  • authorization (SH Admin required, specific role required)

Options

  • header: if token is in a different header, set name of header here

  • isSHAdmin: If set to REQUIRED, user must be SH admin. If set to ALLOW and user is SH admin than other validations are skipped.

@OpenApi: Validation

Lambda OpenApi validation (request/response validation)

Validation of request / response with Swagger.

  • Required is to have valid swagger file on path /src/openapi-doc.yaml.
  • If handler is annotated with @OpenApi than path of handler defined in serverles.yaml (to which is handler bind) must be also defined in swagger file.
  • Request and response is validated

If lambda can be invoked (not as API through AWS Gateway), add configuration invokableLambda.

Options

  • swaggerDocPath: a custom path to swagger file.
  • apiPrefix: when try to find path of handler in swagger file -> this prefix is add. example: when run in AWS and API is deployed to custom domain, all API has prefix which is not part of path of handler.
  • skipResponseValidator: should be validation of response skipped.
  • invokableLambda: If lambda is invoked -> search in swagger file for resource by httpMethod and resource as defined in configuration
invokableLambda: {
  httpMethod: 'GET',
  resource: '/profile/{id}/activities'
}

(if lambda would be invoked without this configuration - swagger validation would fail, resouce would npt be found)

@StatusLogger: API Response and Status handling

AWS Lambda functions are monitored with Elastic (logstash, elasticsearch, kibana, ...). If handler is annotated by this method:

  • and handler returns some entity (JSON object), logged is status "OK"
  • and handler throw exceptions, logged is status "ERROR" and monitoring systems (like Kibana watcher) can raise alert.

AWSLambdaLogger: Common logging

Lambda Error handling And Exceptions

  • use methods in src/types/exception.types.ts