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

public-api-proxy

v2.11.5

Published

The abstraction layer between the public api and integration-hub that accounts for data mapping and traffic shuffling

Downloads

13

Readme

Public API

The public api proxy is built with babel. The npm start script will run the compiled code directly, while invoking nodemon app.js will use the babel require hook for simplicity as you don't have to worry about making sure the build step is being ran.

Route definitions

Each route should be in a routes folder under the desired resource. hapi-router will load routes dynamically. Routes should be separated by the action being performed on the resource. Example: Creating a tax has a route for sending the contract, and a route for checking the status of the asynchronous operation. Those routes could potentially be in a create.js file in the taxes/routes directory.

All handler code should typically remain in the handler function of the route object. If extensive logic is needed and would otherwise make the route object hard to read/change, move the handler function into a controller.js file. Schemas, unless trivial, should live in a schemas folder to keep route definitions as minimal and clean as possible.

You should also take note that any route withe the api tag will return a wrapped response on a successful transaction consisting of the url that was called and the response in a data property. Errors will be sent to the user without being wrapped.

Swagger

There are 2 steps required in order for the swagger plugins to pick up new routes and render them correctly:

  1. Specify the following fields (at a minimum) in the route definition:
{
    method: {String|Array<string>},
    path: String,
    config: {
        description: ''
        tags: ['api', ...], // Tags should also include the primary resource (e.g. hub-taxes, mkt-units, etc)
                            // Note: the primary resource tag must also be added to the ui plugin (see step 2)
        validate: {
            /*
            * Any validation for the route, query, or payload parameter/properties  
            */
        }
        response: {
            schema: Joi.object().description('')
        }
    },
    handler: // Any function that takes the req[uest] and the reply
}
  1. Add the unique primary resource route tag to the defaultTags section of the desired api hapi-swaggered-ui plugin config:
  • For Integration Hub API routes, add to: server/plugins/hapiSwaggeredUiHubApi.js
  • For Inventory Marketplace API routes, add to: server/plugins/hapiSwaggeredUiMktApi.js
{
    register: require('@leisurelink/hapi-swaggered-ui'),
    options: {
        ...
        defaultTags: [
            'hub-pmcs',
            'hub-promotions',
            //Add new primary resource route tags here to include in documentation
        ]
        ...
    }
}

Plugins

To add a new plugin, you can take 1 of 2 steps

  1. Add the name of the plugin to the plugins collections in plugins/index.js and then run npm run build. Use this step if the plugin requires no extra configuration
  2. Add a new file that has the same name as the plugin (with camel casing), add any necessary options or configuration, and then follow step 1 using the file you just created

Index files

With trying to keep confusion at a minimum, index.js files only responsibility should be to gather all other files in the directory and export them back out. Think of index files as a manifest for the directory. If a directory contains only one file and only ever contains one file, remove the directory and just name the js file the same as the directory. This helps avoid the scenario when developing of having 10 different index.js files open at once and cycling through all of them to find the one you want A convenience function has been implemented in mod.js that takes a directory, usually __dirname, requires all the .js or .json files in that directory (excluding index.js, and returns an object keyed by the file name. Index files should be as simple as

import load from 'mod.js'

export default load(__dirname);

Tests

Unit Tests should be separated by the same structure as the file they're testing, so if testing taxes routes, the test directory would be tests/supply/v2/pmcs/taxes/{filename}.tests.js The server object is a global defined in tests/server.tests.js to avoid the problem of walking the directory structure and requiring the server in every test file.