JSPM

  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q77224F
  • License ISC

Generic product database for use in webshops or other places

Package Exports

  • larvitproduct

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (larvitproduct) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Build Status Dependencies

larvitproduct

Generic product module for nodejs.

Product data structure:

{
    "uuid": "string",
    "created": date,
    "attributes": {
        "name": ["Conductor"],
        "price": [200],
        "available color": ["blue", "green"]
    }
}

Installation

npm i --save larvitproduct

Usage

Create new instance of the lib

const {ProductLib} = require('larvitproduct');

const libOptions = {};

libOptions.log = log; // logging instance (see Log in larvitutils library)
libOptions.esIndexName  = 'anEsIndexName';
libOptions.mode = 'noSync'; // see larvitamsync library
libOptions.intercom = new Intercom('loopback interface');
libOptions.amsync = {};
libOptions.amsync.host  = null;
libOptions.amsync.minPort = null;
libOptions.amsync.maxPort = null;
libOptions.elasticsearch = es; // instance of elasticsearch.Client

const productLib = new ProductLib(libOptions, function (err) {
    if (err) throw err;
    // ProductLib instance created!
});

Add a new product

const {ProductLib, Product} = require('larvitproduct');

// Create productLib instance of ProductLib

const product = new Product({'productLib': productLib, 'log': optionalLoggingInstance});
// Or, use the factory function in ProductLib:
const otherProduct = productLib.createProduct(); // will initiate with log instance from productLib

product.attributes = {
    'name': 'Test product #69',
    'price': 99,
    'weight': 14,
    'color': ['blue', 'green']
};

product.save(function (err) {
    if (err) throw err;
    // Product saved!
});