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

mj-legacy-api

v0.0.3

Published

A (terrible) legacy api exists for interacting with a stock system. It returns results asynchronously. The details of the API are included below, and should be generally correct. Using the API complete the following tasks:

Downloads

6

Readme

Terrible Asynchronous API Exercise

A (terrible) legacy api exists for interacting with a stock system. It returns results asynchronously. The details of the API are included below, and should be generally correct. Using the API complete the following tasks:

  1. Lookup the SKU and price, IN ORDER for an apple, a banana and an orange, printed in the format:

    Product: SKU: , Price:

    e.g.

    apple: SKU: a134, Price: 0.99

Remember, the outputted order must be: Apple, Banana, Orange, and it must be the same across multiple runs.

  1. Create a new basket and add the following products (or the maximum available):
  • 4 bananas

  • 16 apples

    e.g. where there are only 3 bananas available, you would add only 3.

    At each point print out the quantity of the products added

    Then confirm the order, printing the returned order-code.

    The expected output should look similar to:

    Adding 3 banana
    Adding 16 apple
    Order confirmed: ORD-1234

API Documentation

Installation

To install the API:

npm install mj-legacy-api

In your code to create an instance of the API Client:

const ApiClient = require('mj-legacy-api');

const api = new ApiClient();

Lookup SKU

Product names will resolve to a Stock Keeping Unit. Prices and Stock can only be looked up against SKU, NOT name.

api.lookupSku(name, callback);

Parameters

  • name: string, name of the product, case insensitive
  • callback: function to call on lookup completion, function will be called with the parameters:
    • error - JS Error object, if successful, error will be undefined.
    • details - object with properties: sku (string)

Errors

On failure to locate product, an error with the message: PRODUCT_NOT_FOUND will be returned.

Lookup Price

api.lookupPrice(sku, callback);

Parameters

  • sku: string, Product SKU, NOT product name
  • callback: function to call on lookup completion, function will be called with the parameters:
    • error - JS Error object, if successful, error will be undefined.
    • details - object with properties: sku (string), price (float)

Errors

On failure to locate product, an error with the message: PRODUCT_NOT_FOUND will be returned.

Lookup Stock

api.lookupStock(sku, callback);

Parameters

  • sku: string, Product SKU, NOT product name
  • callback: function to call on lookup completion, function will be called with the parameters:
    • error - JS Error object, if successful, error will be undefined.
    • details - object with properties: sku (string), stock (integer)

Errors

On failure to locate product, an error with the message: PRODUCT_NOT_FOUND will be returned.

Create Basket

api.createBasket(sku, callback);

Parameters

  • sku: string, Product SKU, NOT product name
  • callback: function to call on basket creation, function will be called with the parameters:
    • error - JS Error object, if successful, error will be undefined.
    • basket - basket object (see below)

Errors

On failure to locate product, an error with the message: PRODUCT_NOT_FOUND will be returned.

Add Product to Basket

basket.add(sku, quantity, callback);

Parameters

  • sku: string, Product SKU, NOT product name
  • quantity: integer, number of products to add
  • callback: function to call on operation completion, function will be called with the parameters:
    • error - JS Error object, if successful, error will be undefined.

Errors

On failure to locate product, an error with the message: PRODUCT_NOT_FOUND will be returned.

On insufficient stock, an error with the message: NOT_ENOUGH_STOCK will be returned.

Confirm Basket Order

basket.confirm(callback);

  • callback: function to call on operation completion, function will be called with the parameters:
    • error - JS Error object, if successful, error will be undefined.
    • reference - string of the order reference