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

@nswhp/af-core-module

v0.1.3

Published

This module provides a base set of core tooling support for Azure Functions for the NodeJS runtime.

Downloads

19

Readme

Azure Function - Core Module

This module provides a base set of core tooling support for Azure Functions for the NodeJS runtime.

Workflow Status Coverage Licence

Bindings

Several Azure Function Binding definitions and Data Services

Models

Errors

The error model definition is build using RFC 7807. Several error class definitions are provided in this module to provide developers with a starting point

When using in conjunction with the azureFunctionWrapper utility function, these error definitions can be used to return HTTP error responses

The following error definitions are included in this module

  • 400 Bad Request
  • 401 Unauthorized
  • 403 Forbidden
  • 415 Unsupported Media Type
  • 500 Internal Server Error

And a custom DownstreamApiError class for handling and proxying errors returned from downstream api requests

An example usage:

const response = await azureFunctionWrapper(async () => {

  // Validate the semantics of the inbound http request

  if (!req.body || req.body === {}) {
    throw new BadRequestError('Missing request body');
  }

  if (!req.headers || !req.headers['Content-Type'] || req.headers['Content-Type'] !== 'application/json') {
    throw new UnsupportedMediaTypeError();
  }

  // ... Call service layer class to handle request business logic

  return apiResponse;
});

return response;
$ curl -X POST  http://localhost:7075/api/otp/_requestOtp -d'{}'
{
  "status": 400,
  "type": "https://httpstatuses.com/400",
  "title": "BAD REQUEST",
  "detail": "Missing request body"
}

Services

Loging Service

The LoggingService provides an inversion layer between the Azure Functions runtime context.log object, and support for other logging implementations.

A ConsoleLogger model is provided in this library for use with the LoggingService.

The Logging Service allows clients to provide a list of log aggregators (log aggregators must implement the Azure Function Logger interface)

An example usage:

const loggingService = new LoggingService(context.log, ConsoleLogger);

loggingService.verbose('Received HTTP Request Body', req.body);
loggingService.info('HTTP trigger function processed a request.');
loggingService.warn('Function Timer Trigger is running late');
loggingService.error('Fatal Error', err);

Axios HTTP Data Service

Axios is the chosen library for HTTP communications with downstream API services. The AxiosHttpDataService class implements the AbstractHttpDataService (which provides a base set of required functionality for developers to implement to make a compliant HTTP data Service.

See the AF App Insights HTTP Data Service for an App Insights enabled HTTP client

An example usage:

const http = new AxiosHttpDataService(Axios);
const response = await http.makeHttpGetCall('https://www.google.com');

Utilities

The azureFunctionWrapper provides a simple to use wrapper for any HTTP based Azure Function trigger. It safely returns a HTTP Response object model for a controller router and also safely handles exception error handling.

An example usage:


export class VersionController {

  constructor(
    private readonly versionService: IVersionService
  ) { }

  /**
   * GET api for /version
   * Returns the semantically tagged build number of the API
   * @param req The inbound HTTP Request
   */
  async getVersion(req: HttpRequest): Promise<IHttpResponse<IVersionMessage | IHttpErrorResponse>> {

    const response = await azureFunctionWrapper(async () => {
      
      // Code executed inside the azureFunctionWrapper can run safely
      // with error handling in place to catch errors thrown and represent them
      // as a HTTP Error Response

      const version = await this.versionService.getVersion();
      const apiResponse: IApiResponse<IVersionMessage> = {
        body: version,
        status: 200 // Success
      };

      return apiResponse;

    });

    return response;
  }

}